Automate the Creation of the EXE File

Code snippets illustrating how LBB can be used
xxgeek
Posts: 13
Joined: Tue Nov 28, 2023 1:36 pm

Automate the Creation of the EXE File

Post by xxgeek »

Hello everyone, this is my first post in the LB Booster forum.
My programming skills are intermediate at best, newbie beginner at my worst..
Even though I've spend a lot of time with many different languages over the years, I have never pushed myself to anywhere near expert level. But I love writing and reading code, and I persevere.

I use LB Booster, but only(so far) to boost my Liberty Basic bas files and create the boosted exe files

That said I have developed a program to automate the progress. It isn't perfect but here on my PC it gets the job done.
The issue with others would be the timing of the automation. If anyone wishes to take a look, and help make it better I'm all ears and appreciate the help.

The size of the .bas file selected, and the capability of the Users hardware need to be addressed somehow in the code.
Please read the top of the code for instructions and a better understanding of how it works.

The code

Code: Select all

'QuickEXE using LB Booster (Automated)
'Download LBB.exe and LBRUN.exe from this page - http://lbbooster.com/
'Save them to the same folder as this file RUN's from (DefaultDir$)
'created by xxgeek
'Sept 2023
'Edited Nov 2023

Be AWARE
'Copy this code to a file in a folder of it's own before RUN'ing (QuickEXE will create files in it's folder)
'QuickEXE:
'Copies the selected .bas file to DefaultDir$, then automates LBB exe file creation to create the new EXE file in DefaultDir$(same folder this code is RUN'ing from)
'Overwrites any existing .bas file of same name in DefaultDir$.Does not affect Original file
'If existing EXE file of same name resides in DefaultDir$ Automation Stops
'_ and the User is asked to Overwrite. Does not affect Original unless confirmed by user.
'_ the User must manually close the Information window showing the path to "Saved As" file

'There may be a window pop up asking to overwrite an existing exe file of same name
'The automation takes care of that too after a couple of seconds, defaulted to "No" by design" :)

'Please Wait Long Enough
'If you wait, and no existing filename of the new exe file exists, all open windows will/should close eventually. No need to start closing windows manually, and if you do will most likely cause a crash, or no exe file.
'Very tricky timing things in the code to suit any file size, or any old PC.
'If you have issues, we can try to work them out.
    nomainwin
[LBB_EXE]
    filedialog "Open a Liberty Basic Source File (.bas) ", "c:\*.bas", fname$
 if instr(fname$, DefaultDir$) then notice chr$(13);"Selecting a File from within DefaultDir$ is NOT ALLOWED";chr$(13);chr$(13);"Try Again With a Different File" : end
    if fname$ = "" then wait
    cursor hourglass
    LBB$ = DefaultDir$;"\LBB.exe"
    fname0$ = GetFilename$(fname$)
    open fname$ for input as #1
    open fname0$ for output as #2
    #2 input$(#1, lof(#1))
    close #1
    close #2
    call writeAutoSaveLBB
    run "wscript ";autoSaveLBB$
    run LBB$;" -C -M -A ";DefaultDir$;"\";fname0$
    selected$ = left$(fname0$, len(fname0$)-4)
    do
    scan
    loop until fileExists(DefaultDir$, selected$;".exe")
    call pause 9000
    kill DefaultDir$;"\";autoSaveLBB$
    file$ = selected$;".exe"
    if fileExists(DefaultDir$, file$) then
    run "explorer /select, ";file$
    else
    notice file$;" was NOT Created"
    end if
    cursor normal
    end

sub writeAutoSaveLBB
    q$ = chr$(34)
    global autoSaveLBB$
    autoSaveLBB$ = "autoSaveLBB.vbs"
    open autoSaveLBB$ for output as #1
    #1 "Set WshShell = WScript.CreateObject(";q$;"WScript.Shell";q$;")"
    #1 "Do While Not WshShell.AppActivate(";q$;"Save standalone executable";q$;")"
    #1 "Loop"
    #1 "WshShell.AppActivate(";q$;"Save standalone executable";q$;")"
    #1 "WshShell.SendKeys ";q$;"{ENTER}";q$
    #1 "Wscript.Sleep(8000)"
    #1 "WshShell.SendKeys ";q$;"{ENTER}";q$
    #1 "Set WshShell = nothing"
    close #1
end sub

'sub to  create pauses in program
sub pause mil
    t=time$("ms")+mil
    while time$("ms")<t
        scan
    wend
end sub

'function for checking file existence
function fileExists(path$, filename$)
    dim info$(0, 0)
    files path$, filename$, info$()
    fileExists = val(info$(0, 0)) 'non zero is true
end function

'function to separate filename from full path to file
function GetFilename$(fileName$)
    i = len(fileName$)
    while mid$(fileName$, i, 1) <> "\" and mid$(fileName$, i, 1) <> ""
        i = i-1
    wend
    GetFilename$ = mid$(fileName$, i+1)
end function
  
guest
Site Admin
Posts: 197
Joined: Tue Apr 03, 2018 1:34 pm

Re: Automate the Creation of the EXE File

Post by guest »

xxgeek wrote: Tue Nov 28, 2023 2:13 pm I have developed a program to automate the progress.
Good work! As you say it can be difficult to make SendKeys automation reliable.

I think I'm right in saying that if there's an existing EXE (in the default location) the various fields in the Compile dialog are automatically populated from that file, which hopefully simplifies things.
xxgeek
Posts: 13
Joined: Tue Nov 28, 2023 1:36 pm

Re: Automate the Creation of the EXE File

Post by xxgeek »

I think I'm right in saying that if there's an existing EXE (in the default location) the various fields in the Compile dialog are automatically populated from that file, which hopefully simplifies things.
I'll need to do some research on "the various fields in the Compile dialog"
Also wondering if LBB has any command line switches I may be able to take advantage of.
I'll look through the documentation.

Thanks for the response.
xxgeek
Posts: 13
Joined: Tue Nov 28, 2023 1:36 pm

Re: Automate the Creation of the EXE File

Post by xxgeek »

I just lucked onto a better more reliable way to verify the created exe file.
It removes the 9 second pause, and replaces it with a second verification loop.
I also commented the line to kill the created .vbs file. Why keep writing the same file over and over, and deleting it.

Also once the exe file is created, File Explorer will open to the new exe file.

replaced

Code: Select all

 
    'call pause 9000
    'kill DefaultDir$;"\";autoSaveLBB$
 
with

Code: Select all

    do
    scan
    loop until fileExists(DefaultDir$, selected$;".exe")
      
And added

Code: Select all

     if fileExists(DefaultDir$, selected$;".exe") then
    run "explorer /select, ";selected$;".exe"
    else
    notice selected$;".exe was NOT Created"
    end if
 
The new code

Code: Select all

 
'QuickEXE using LB Booster (Automated)
'Download LBB.exe and LBRUN.exe from this page - http://lbbooster.com/
'Save them to the same folder as this file RUN's from (DefaultDir$)
'created by xxgeek
'Sept 2023
'Edited Nov 2023

'Be AWARE
'Copy this code to a file in a folder of it's own before RUN'ing (QuickEXE will create files in it's folder)
'QuickEXE:
'Copies the selected .bas file to DefaultDir$, then automates LBB exe file creation to create the new EXE file in DefaultDir$(same folder this code is RUN'ing from)
'Overwrites any existing .bas file of same name in DefaultDir$.Does not affect Original file
'If existing EXE file of same name resides in DefaultDir$ Automation Stops
'_ and the User is asked to Overwrite. Does not affect Original unless confirmed by user.
'_ the User must manually close the Information window showing the path to "Saved As" file

'There may be a window pop up asking to overwrite an existing exe file of same name
'The automation takes care of that too after a couple of seconds, defaulted to "No" by design" :)

'Please Wait Long Enough
'If you wait, and no existing filename of the new exe file exists, all open windows will/should close eventually. No need to start closing windows manually, and if you do will most likely cause a crash, or no exe file.
'Very tricky timing things in the code to suit any file size, or any old PC.
'If you have issues, we can try to work them out.

'NOTE: If your .bas won't pass the LB Booster compiler check, creating the exe won't work.

    nomainwin
[LBB_EXE]
    filedialog "Open a Liberty Basic Source File (.bas) ", "c:\*.bas", fname$
 if instr(fname$, DefaultDir$) then notice chr$(13);"Selecting a File from within DefaultDir$ is NOT ALLOWED";chr$(13);chr$(13);"Try Again With a Different File" : end
    if fname$ = "" then wait
    cursor hourglass
    LBB$ = DefaultDir$;"\LBB.exe"
    fname0$ = GetFilename$(fname$)
    open fname$ for input as #1
    open fname0$ for output as #2
    #2 input$(#1, lof(#1))
    close #1
    close #2
    call writeAutoSaveLBB
    run "wscript ";autoSaveLBB$
    run LBB$;" -C -M -A ";DefaultDir$;"\";fname0$
    selected$ = left$(fname0$, len(fname0$)-4)
    do
    scan
    loop until fileExists(DefaultDir$, selected$;".exe")
    do
    scan
    loop until fileExists(DefaultDir$, selected$;".exe")
    if fileExists(DefaultDir$, selected$;".exe") then
    run "explorer /select, ";selected$;".exe"
    else
    notice selected$;".exe was NOT Created"
    end if
    cursor normal
    end

sub writeAutoSaveLBB
    q$ = chr$(34)
    global autoSaveLBB$
    autoSaveLBB$ = "autoSaveLBB.vbs"
    open autoSaveLBB$ for output as #1
    #1 "Set WshShell = WScript.CreateObject(";q$;"WScript.Shell";q$;")"
    #1 "Do While Not WshShell.AppActivate(";q$;"Save standalone executable";q$;")"
    #1 "Loop"
    #1 "WshShell.AppActivate(";q$;"Save standalone executable";q$;")"
    #1 "WshShell.SendKeys ";q$;"{ENTER}";q$
    #1 "Wscript.Sleep(10000)"
    #1 "WshShell.SendKeys ";q$;"{ENTER}";q$
    #1 "Set WshShell = nothing"
    close #1
end sub

'function for checking file existence
function fileExists(path$, filename$)
    dim info$(0, 0)
    files path$, filename$, info$()
    fileExists = val(info$(0, 0)) 'non zero is true
end function

'function to separate filename from full path to file
function GetFilename$(fileName$)
    i = len(fileName$)
    while mid$(fileName$, i, 1) <> "\" and mid$(fileName$, i, 1) <> ""
        i = i-1
    wend
    GetFilename$ = mid$(fileName$, i+1)
end function