1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

Legacy GM [SOLVED] Store entire text file contents in string (GM 8.1)

Discussion in 'Programming' started by Samuel Venable, Jan 12, 2018.

  1. Samuel Venable

    Samuel Venable Time Killer

    Joined:
    Sep 13, 2016
    Posts:
    1,299
    I wrote a script for my Execute Statement extension which allows me to read the entire contents of a VBScript text file. It works in GMStuido 1.4 and 2. But for whatever reason I can't get it working in GM 8.1. It's obvious legacy GM can do this too, but needs to be done slightly different in order for it to work, I just can't remember how it used to be done.

    Code:
    // ExecuteVBScriptFile executes .VBS script files.
    // argument0: The VBScript script file to execute.
    
    if (file_exists(argument0) == true) {
    
        var __vbsFile__, __vbsString__;
    
        __vbsFile__   = file_text_open_read(argument0);
        __vbsString__ = "";
    
        while (file_text_eof(__vbsFile__) == false) {
    
            __vbsString__ += file_text_readln(__vbsFile__);
    
        }
    
        file_text_close(__vbsFile__);
    
        ExecuteStatement(__vbsString__, "VBScript");
    
    } else {
    
        show_message("File not found!");
    
    }
    Anyone know what I should do differently?

    Thanks!
    Samuel
     
  2. CedSharp

    CedSharp Member

    Joined:
    Sep 5, 2016
    Posts:
    665
    The code you posed seems perfectly fine.
    Try doing a show_message(__vbsString__);
    I suspect it's related to the DLL loading code instead.
     
    Samuel Venable likes this.
  3. trg601

    trg601 Member

    Joined:
    Jun 21, 2016
    Posts:
    151
    I was actually working with GM8 recently and encountered a similar problem.
    In GM8, the function file_text_readln() doesn't return a string like it does in GMS. From the documention:
    Since file_text_read_string() reads the whole line you need to do this instead:
    Code:
    __vbsString__ += file_text_read_string(__vbsFile__);
    file_text_readln(__vbsFile__);
     
    Samuel Venable and CedSharp like this.
  4. Samuel Venable

    Samuel Venable Time Killer

    Joined:
    Sep 13, 2016
    Posts:
    1,299
    Thanks guys for your responses! :D
    I tried your suggestion, (already, actually), and added a show_message() to see why it still wasn't working:
    Code:
    // ExecuteVBScriptFile executes .VBS script files.
    // argument0: The VBScript script file to execute.
    
    if (file_exists(argument0) == true) {
    
        var __vbsFile__, __vbsString__;
    
        __vbsFile__   = file_text_open_read(argument0);
        __vbsString__ = "";
    
        while (file_text_eof(__vbsFile__) == false) {
    
            __vbsString__ += file_text_read_string(__vbsFile__);
            file_text_readln(__vbsFile__);
    
        }
    
        file_text_close(__vbsFile__);
     
        show_message(__vbsString__);
     
        ExecuteStatement(__vbsString__, "VBScript");
    
    } else {
    
        show_message("File not found!");
    
    }
    This is the result:

    Untitled.png

    VBScript needs to have new lines of code separated, instead it's being treated like it's all on the same line. Thus, I am still feeding msscript.ocx invalid VBScript.

    Here's the actual contents of the VBS file I'm using, for anyone who's interested in seeing:
    Code:
    Set Screen = CreateObject("InternetExplorer.Application")
    Screen.FullScreen = True
    Screen.TheaterMode = True
    ScreenWidth = Screen.Width
    ScreenHeight = Screen.Height
    Screen.Quit
    
    Set objShell = CreateObject("Wscript.Shell")
    Set IE = CreateObject("InternetExplorer.Application")
    
    Sub CheckIt
    
        If IE.document.parentWindow.event.keycode = 27 Then bEsc = True
    
    End Sub
    
    With IE
    
        .FullScreen = True
        .TheaterMode = True
        .MenuBar = False
        .StatusBar = False
        .ToolBar = False
        .Resizable = False
        .Width = 640
        .Height = 480
        .ClientToWindow .Width, .Height
        .Left = (ScreenWidth / 2) - (.Width / 2)
        .Top = (ScreenHeight / 2) - (.Height / 2)
        .Navigate "http://www.yoyogames.com/"
        .Visible = True
    
        Set Processes = GetObject("winmgmts:").InstancesOf("Win32_Process")
    
        intProcessId = ""
    
        For Each Process In Processes
     
            If StrComp(Process.Name, "iexplore.exe", vbTextCompare) = 0 Then
         
                intProcessId = Process.ProcessId
                Exit For
     
            End If
    
        Next
    
        If Len(intProcessId) > 0 Then
     
            objShell.AppActivate intProcessId
    
        End If
    
        If .FullScreen = True Or .TheaterMode = True Then
    
            Do While bEsc = False And (err.number = 0)
    
                Do While .Busy
    
                    Dim dteWait
                    dteWait = DateAdd("s", 0.000001, Now())
    
                    Do Until (Now() > dteWait)
                    Loop
    
                Loop
    
                Set .document.body.onkeypress = GetRef("CheckIt")
    
                For i = 1 To 100
    
                    If (err.number <> 0) Or bEsc Then Exit Do
    
                Next
    
            Loop
    
            .Visible = False
            .Quit
    
        End If
    
    End With
    ...though I did modify it very slightly since the time of that screenshot.

    Again, the code loads and executes fine in GMStudio 1&2, and using that same code above written in the IDE, (in quotes), instead of an external file, works in GM 8.1. So the problem I'm 99.99% isn't the DLL's code, though I could be wrong. The only thing that isn't working in 8.1 is loading it from a file, which is being completely done in GML.
     
    Last edited: Jan 14, 2018
  5. CedSharp

    CedSharp Member

    Joined:
    Sep 5, 2016
    Posts:
    665
    Try to add the \n and \r characters yourself:
    Code:
    __vbsString__ += file_text_read_string(__vbsFile__);
    file_text_readln(__vbsFile__);
    __vbsString__ += chr(10)+chr(13);
    Here are what unicode 10 and unicode 13 represent:
    [​IMG]

    10 = Line Feed: This moves the caret down one line.
    13 = Carriage Return: This moves the caret back at the start of the current line.
     
    Samuel Venable likes this.
  6. Samuel Venable

    Samuel Venable Time Killer

    Joined:
    Sep 13, 2016
    Posts:
    1,299
    That did it! Thank you so much @CedSharp!!! :D
     
  7. CedSharp

    CedSharp Member

    Joined:
    Sep 5, 2016
    Posts:
    665
    Glad this did the trick. I remembered that GameMaker 8.1 and before used '#' for newlines, but GameMaker studio uses the actual \n\r sequence.
    Seems all you have to do is add it yourself if any external tool reads your strings.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice