BAS<2>EXE - Convert .bas files to exe (3 methods)

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

BAS<2>EXE - Convert .bas files to exe (3 methods)

Post by xxgeek »

P.S. IMPORTANT - Before running - Place file in it's own Folder. Many files and Folders will be created.

BAS2EXE v1.9.2c with commandline support for Liberty Basic is a program I have been working on since my first days with
Just Basic v2.0 approximately 2 years ago. I have been adding features to it as I learn more about JB and LB and now LB
Booster.
I hope it will help others with their programming efforts.

Basically - A window appears to select a few features and then press [Select File] to select a working .bas file for conversion to .exe. Once a file is selected, just sit back and watch the action for best results.

If you wait, and don't click any of the windows that open, they should ALL eventually close on their own.
Please let me know if they don't close automatically. The whole idea is to automate the entire process.
Be aware, small files will seem to take longer to close the open windows and dialogs.

BAS2EXE can be used from the commandline if you are in DefaultDir$
Plus better support is optional from a Windows command prompt - see Top of code for further command line switches syntax and use.

Please report any issues, and give feedback as to how it is working for you, and what OS you use. PC specs would also help. Thanks.

If LB Booster is selected to create the exe file ....
- First time, it will ask to download LBB.exe from the LB Booster website
From then on, if downloaded, it will not ask again.


EXE Creation
Method 1 - Gathers all the required DLL,SLL, and Runtime files. Renames the runtime exe to same name as .bas file selected. Also creates the tkn file. This method is always done no matter users choice because the tkn file is needed when using IEXPRESS, but can be deleted by deselecting [Keep Project] checkbox .

Method 2 - Uses IEXPRESS, built into Windows to create a single self extracting exe file (this is the default method).
-These exe files open in the users %temp% dir and when these exe's are closed, all the files get deleted
-So not good for .bas files that need to save to files in DefaultDir$

Method 3 - Uses LB Booster to create the exe files.
-These exe's when run unpack to the DefaultDir$ so nothing gets deleted when they are closed.


Any questions, or requests please feel free to ask.
Enjoy!

Code: Select all

     ' Use at your own risk - Author accepts NO liabilities
    ' Author - xxgeek, a member of the      justbasiccom.proboards.com/     forums
    'BAS2EXE v1.9.2c - New Version - Feb1 2024

    ' Title - BAS2EXE v1.9.2c      (with 'Optional' CommandLine support)
    ' For Windows 10 (possibly XP, 7, 8 and 11) - try it and let me know
    ' Date Introduced to Public = Jan 29 2023
    ' {Purpose} - To automate bas file to exe file (self extracting exe) making creation quick and easy while
    ' storing dated copies (users choice), of every selected bas file, the created tkn, and the created exe (self extracting)
    ' exe file containing the dll files, sll files, jbrun2.exe(renamed to same name as .bas file selected)
    ' Along with that there is a project folder created holding the same files as the exe that gets updated
    ' if and when the same bas file is selected, Note, the dated files are in their appropriate folders, EXE, TKN, and BAS
    ' NOTE -They will be overwritten if the same .bas file is selected on the same day within one minute
    ' The options are user generated by selecting the appropriate checkboxes (GUI)
    ' Or by Using the appropriate switches (Command Mode)

    'GUI MODE

    ' Place this bas file in it's own folder as it will create some folders and temp files as well as the above
    ' Choose 32bit exe or 64`bit exe - defaults to 64 bit if no selection made
    '  Option to password the EXE file - Check off the checkbox, [Select File] and enter a password when prompted.
    '  When bas2exe opens a filedialog to choose a bas file choose a bas file that is a
    ' _good working bas file (or there will be trouble with the compiler)
    ' Add a version number and or Date/Time stamp the EXE filename
    ' View the Menu after EXE file creation
    'The "Save tkn" file dialog and the Information "saved as" dialog close automatically and save the tkn file to where it is needed.

    ' If you keep the project folders you will have a "project" folder with each saved project which
    '_ includes the dll, sll files and jbrun2.exe(renamed), the selected .bas file and the tkn file.
    'The EXE File is saved to the EXE folder in the same folder as this program is located.
    ' _unless otherwise specified  for eg: when using the (CommandLine) and not the GUI (no GUI option for destination - v2.0 maybe )
    ' Next Window is to choose to Run the EXE or view the EXE Files Created by this Program
    '_ or Make a New EXE
    ' Note - For standalone bas files only with no dependent files or folders - at this time (Maybe Version 2, we'll see)
    ' If the .bas file you select runs in the LB IDE when RUN,  the EXE will be made. If there are programming
    '_ runtime errors your EXE could still crash at some point (Not BAS2EXE's fault)
    ' If it won't run in the LB IDE there will be an error reported by the JB compiler when this app attempts to
    '_ make the tkn file, and the LB window that opens showing the code for the selected bas file will stay opened
    '_, close it manually.

    'IMPORTANT INFORMATION

    ' This new version has CommandLine support, meaning it works from a command prompt.
    ' or it can be used in code projects with the Run command as well.

    'COMMAND MODE

    ' Syntax for commandline:
    ' If using the EXE
    '   b2e -sourceFilePath\file.bas -destinationPath /bas /dt /kp /pw /r /s /tkn /v'number' /bit'number'
    ' or b2e.exe -sourceFilePath\file.bas -destinationPath /bas /dt /kp /pw /r /s /tkn /v'number' /bit'number'

    ' If using the TKN in code
    '   b2e.tkn -sourceFilePath\file.bas -destinationPath /bas /dt /kp /pw /r /s /tkn /v'number' /bit'number'

    ' if destinationPath is ommtted the default destinationPath is DefaultDir$\EXE
    ' If sourcePath\file.bas is ommitted BAS2EXE defaults to opening in GUI mode
    ' If no switches used, all switches defaults are false, 0 or "", except for the bit64 default
    ' Switches MUST be separated with a 'space'
    ' Switches are Optional
    ' Just typing b2e by itself BAS2EXE defaults to opening in GUI mode

    'Switches
    '   /bas    - saves a dated backup of the selected bas file
    '   /bit32 - creates a 32 bit exe file
    '   /bit64 - creates a 64 bit exe file (Defaults to 64bit EXE file if no swtich used)
    '   /dt   - appends date/time to the created exe filename.
    '   /kp  - saves the Project Folder (tkn, renamed jbrun2.exe dll and sll files) Created anyway - they are needed for the EXE file.
    '   /pw  - Prompts user for a password to open the created EXE file (If used the EXE file won't run without it, so save the password somewhere safe.)
    '   /q  - Stops the "Please Wait" activity window from appearing while in command mode.
    '   /r   - Runs the New EXE file after it is created
    '   /s  - shows the Post Creation EXE Menu Window (GUI) to (View / Run / MakeNew - EXE file)
    '   /tkn   -  saves a dated backup of the tkn file.
    '  /v'number' - appends the EXE filename with a version number or text
    ' (No Spaces) examples:      /v2.51      /v.001      /v123.Any_thing  Note: The "v" is not included.
    ' If you want a v in your EXE filename then you must add one eg:   /vv4.5.1   /vvTest123  etc

    ' Here are some examples of commandline use.
    '   eg:    b2e       (alone this opens the GUI)
    '            b2e -sourceFilePath\file.bas       (Creates a single exe file in DefaultDir$\EXE) no project folder, no backups, no appended date/time, or version etc
    '            b2e -sourceFilePath\file.bas -f:\MyStuff\MyEXEcollection      Creates a single 64bit EXE file in f:\MyStuff\MyEXEcollection
    '            b2e -sourceFilePath\file.bas /bas /bit32 /dt /kp /pw /q /r /s /tkn /vv1.0    (Creates a single 32bit exe file in DefaultDir$\EXE)
    '             _ including all the optional swtches
    ' Switches can be in ANY order as long as they preceed the -path(s)
    ' if -sourceFilePath\file.bas is a lone .bas file with no path, BAS2EXE assumes the file is in the DefaultDir$
    ' The dashes before the path(S) ARE necessaary
    ' the spaces between the switches ARE necessary

    ' Please NOTE - About the app and it's limitations
    'By Default This app uses a built in Windows app named IEXPRESS to create the EXE file by way of a SED (Self Extracting Directive) file.
    ' This app write the SED file, then IEXPRESS reads, and executes the instructions in it to create the EXE file.
    ' IEXPRESS has limits.
    ' It won't copy a folder, so for now this app can only create EXE files with the necessary runtime support files
    ' That means (for now anyway) the files needed to work (dll's, sll's tkn renamed jbrun2.exe and the bas file if user wants it.)
    ' If your .bas file uses any support files from the DefaultDir$ or sub folders of DefaultDir$ such as
    ' _bmp, txt, etc, they won't be in the EXE file when created.
    ' The app is great for testing, or for apps that need no support files (other than the jb dlls/slls the tkn and renamed jbrun2.exe )
    ' _and if your .bas doesn't create any files needed the next time it is opened.

    ' When an EXE that is created by IEXPRESS executes, it is unpacked in the users temp folder, into a folder
    ' _named IXP001.tmp, or the number can vary on each persons PC.     IXP001......IXP00n  (depends on other temp apps I guess)
    ' These temp folders get deleted when the app is finished doing it's thing as is closed.
    ' That means if your app saves any data to files in DefaultDir$, or copies any files\folders to DefaultDir$, they get deleted too.

    ' If the interest is there, and I get some feedback on this app I'll work on a version 2.
    ' Version 2 will have support for adding extra folders and files to the EXE
    ' It will also get around the temp folder issue. I have that part working already.
    ' It may also have an option to batch create the EXE files.
    ' By having .bas files in a folder, and executing a loop to create one after the other.
    ' Other suggestions are welcome

    ' If you use this, please take the time to give some feedback so I know what's up,
    ' Any issues, don't hesitate to report them
    ' This App is actually part of a larger app, and the defaults are set 'as is' to accomodate the larger app.
    'v1.9.2 adds an option to use LB Booster to create the exe file
    'EXE files created using LB Booster automated unpack into DefaultDir$
    'So new files etc are not deleted as with IEXPRESS
    ' I didn't want to re-write the whole thing for the 1 person that 'may' use it.
    ' This app is free to use, edit, and/or distibute. Feel free to make it work the way you want it to.

    global q$, upath$, fixedDate$, fixedTime$, autoSave$
    on error goto [abort]
    nomainwin
    call getUserPath
    upath$ = trim$(upath$)
    'Uncommenting the next 3 lines of code will copy BAS2EXE into Users Home Dir, and
    'Create a shortcut in the Panel to Start BAS2EXE
    'This allows for commandline support for BAS2EXE using CMD.exe (or command line)
    'if not(fileExists(DefaultDir$, "b2e.exe")) then
    'command = 1 : firstRun = 1 : project = 1 : fname$ = DefaultDir$;"\b2e.bas" : goto [checkLBpath]
    'end if

[TOP]
    if mainOpen = 1 then close #main : mainOpen = 0
    p = 0 : project = 0 : tkn = 0 : bas = 0 : ve$ = "" : ve = 0 : project = 0 : incbas = 0 : dt = 0 : fname$ = "" : exeDest$ = "" : LBpath$ = "" : selectedpath$ = ""
    q$ = chr$(34)
    if CommandLine$ <> "" then
        if not(instr(CommandLine$, ".bas")) then [GUI]
        sourc3$ = word$(CommandLine$, 3)
        sourc2$ = word$(CommandLine$, 2)
        sourc1$ = word$(CommandLine$, 1)
        sourc = 1
        if instr(sourc1$, ".bas") then fname$ = word$(CommandLine$, 1) : goto [getDest]
        sourc = 2
        if instr(sourc2$, ".bas") then fname$ = word$(CommandLine$, 2) : goto [getDest]
        sourc = 3
        if instr(sourc3$, ".bas") then fname$ = word$(CommandLine$, 3)
[getDest]
        fname$ = trim$(fname$)
        if right$(fname$, 1) = chr$(34) then fname$ = left$(fname$, len(fname$)-1)
        if left$(fname$, 1) = chr$(34) then fname$ = right$(fname$, len(fname$)-1)
        if left$(fname$ ,1) = "-" then fname$ = right$(fname$, len(fname$)-1)
        if left$(fname$ ,1) = "\" then fname$ = right$(fname$, len(fname$)-1)
        fname$ = trim$(fname$)
        if left$(fname$ ,1) = "\" then fname$ = right$(fname$, len(fname$)-1)
        if not(instr(fname$, ":\")) and instr(fname$, ".bas") then fname$ = DefaultDir$;"\";fname$
        dest$ = word$(CommandLine$, 2)
        if instr(dest$, ":\") and sourc = 1 then exeDest$ = word$(CommandLine$, 2) : goto [gotDest]
        dest$ = word$(CommandLine$, 3)
        if instr(dest$, ":\") and sourc = 2 then exeDest$ = word$(CommandLine$, 3) : goto [gotDest]
        dest$ = word$(CommandLine$, 4)
        if instr(dest$, ":\") and sourc = 3 then exeDest$ = word$(CommandLine$, 4) : goto [gotDest]
        exeDest$ = DefaultDir$;"\EXE"
[gotDest]
        if left$(exeDest$ , 1) = "-" then exeDest$ = right$(exeDest$, len(exeDest$)-1)
        if right$(exeDest$, 1) = chr$(34) then exeDest$ = left$(exeDest$, len(exeDest$)-1)
        if left$(exeDest$, 1) = chr$(34) then exeDest$ = right$(exeDest$, len(exeDest$)-1)
        if left$(exeDest$ , 1) = "-" then exeDest$ = right$(exeDest$, len(exeDest$)-1)
        if instr(CommandLine$, "/bas") then bas = 1      'creates a dated backup of the user selected .BAS file in DefaultDir$\BAS
        if instr(CommandLine$, "/dt") then dt = 1           'appends the date and time to the EXE file
        if instr(CommandLine$, "/kp") then project = 1  'keep the project folder (temp project folder gets deleted by default in command mode)
        if instr(CommandLine$, "/pw") then p = 1          'password - adds password to bas file - if chosen, the EXE file won't run without it.
        if instr(CommandLine$, "/q") then quiet = 1       'no "please wait" window will appear
        if instr(CommandLine$, "/r") then runEXE = 1    'Run the newly created exe file.
        if instr(CommandLine$, "/s") then show = 1       'show final options window (defaults to not show in command mode)
        if instr(CommandLine$, "/tkn") then tkn = 1       'creates a dated backup of the user selected TKN file in DefaultDir$\TKN
        if instr(CommandLine$, "/v") then                'ALL CommandLine options default to false,  '0' , "", unless switch options are utilized
            ve = 1                                                      ' appends a version number to the EXE filename - defaults to false - 0
            ve$ = word$(CommandLine$, 2 , "/v") : ve$ = word$(ve$, 1)
        end if
        bit = 64
        if instr(CommandLine$, "/bit") then
            bit$ = word$(CommandLine$, 2 , "/bit") : bit$ = word$(bit$, 1) : bit = val(bit$)
        end if
        LBpath$ = "C:\Program Files (x86)\Liberty Basic v4.5.1"
        command = 1 : goto  [checkLBpath]
    end if
[GUI]
    exeDest$ = ""
    titlebar$ =  "BAS2EXE v1.9.2c"

[checkLBpath]
    LBpath$ = "c:\Program Files (x86)\Liberty Basic v4.5.1"
    'check Liberty Basic v4.5.1 Default Install Dir for existence
    'if Liberty Basic v4.5.1 is NOT installed to it's Default Install Dir, get Path from User using folder dialog
    if pathExists(LBpath$) then [go] else notice chr$(13)+" Liberty Basic v4.5.1 was not installed to the default install folder." +chr$(13)+"Hit [ok], then Select the Folder Liberty Basic v4.5.1 is Installed"
    'if folder path chosen by user for Liberty Basic install is wrong catch error later with check for jbrun2.exe
    a$ = FolderDialog$("Select Your Liberty Basic v4.5.1 Install Folder")
    if a$ = "" then notice chr$(13);"Liberty Basic v4.5.1 must be installed to continue";chr$(13);chr$(13);"BAS2EXE will now close" : end
    LBpath$ = a$
[go]
    if command = 1 then [commandPath]
    ' setup a Window for User to Select a .bas File, to select options for the EXE file.
    WindowWidth = 600
    WindowHeight = 400
    UpperLeftX=INT((DisplayWidth-WindowWidth)/2)
    UpperLeftY=INT((DisplayHeight-WindowHeight)/2)
    BackgroundColor$ = "lightgray"
    ForegroundColor$ = "black"

    'add some text ,some buttons, and checkboxes to the Window
    statictext #pick.exe, "EXE File", 35, 30, 95, 30
    statictext #pick.head, "BAS<2>EXE v1.9.2c", 200, 5, 210, 30
    statictext #pick.temp, "Project Files", 425, 80, 195, 30
    statictext #pick.datedtext, "Dated Backups", 225, 80, 185, 30
    statictext #pick.info, "Select a working Liberty Basic Source Code File (.bas)", 100, 270, 590, 30
    button #pick.default, "Select File", [defaultClick],UL 140, 300, 135, 35
    button #pick.jbforums, "Visit the Liberty Basic Forums @ https://libertybasiccom.proboards.com/", [forumLink],UL 0, 355, 595, 20
    checkbox #pick.opendest, "Open Destination Dir When Finished", [OpenDest], [noOpenDest], 20, 210, 250, 20
    checkbox #pick.bit32, "32 Bit", [bit32], [nobit32], 20, 65, 50, 20
    checkbox #pick.bit64, "64 Bit", [bit64], [nobit64], 75, 65, 50, 20
    checkbox #pick.password, "Add a Password", [yespass], [nopass], 20, 90, 140, 20
    checkbox #pick.appDT, "Append Date/Time", [appDT], [noappDT], 20, 115, 140, 20
    checkbox #pick.appversion, "Append Version Number", [appVersion], [noappVersion], 20, 140, 140, 20
    checkbox #pick.project, "Keep Project Dir", [project], [noproject], 430, 115, 165, 20
    checkbox #pick.TKN, "SaveTKN File", [noTKN], [yesTKN], 250, 115, 140, 20
    checkbox #pick.BAS,"Save BAS File", [noBAS], [yesBAS], 250, 140, 140, 20
    checkbox #pick.LBB,"Use LB Booster Instead of IEXPRESS to Create the Single EXE File", [yesLBB], [noLBB], 90, 245, 440, 20
    checkbox #pick.ShowOptionsMenu,"Show Post Creation Options Menu", [noShow], [yesShow], 20, 190, 190, 20
    button #pick.32, "Cancel", [cancel],UL 320, 300, 135, 35
    statictext #pick.versionText, "Version #", 40, 170, 50, 20
    textbox #pick.ve, 90, 165, 85, 20
    'open the Window, and set some Fonts for each statictext, and buttons
    open "BAS2EXE v1.9.2c (CommandLine Support)" for dialog as #pick : pickOpen = 1
    #pick, "trapclose [cancel]"
    #pick.exe, "!font Arial_bold"
    #pick.temp, "!font Arial_bold"
    #pick.datedtext, "!font Arial_bold"
    #pick.info, "!font Arial_bold"
    #pick.head "!font Arial 16 bold"
    #pick.bit64, "set"
    #pick.project, "set"
    #pick.TKN "set"
    #pick.BAS "set"
    #pick.appDT "set"
    #pick.ShowOptionsMenu "set"
    #pick.opendest "set"
    #pick.versionText "!hide"
    #pick.ve "!hide"
    #pick.LBB "font arial 10 bold"
    #pick.default, "!setfocus"
    show = 1
    project = 1
    tkn = 1
    bas = 1
    bit = 64
    dt = 1
    openDest = 1
    wait

    ''temp files saved or not (user choice)
[OpenDest]
    #pick.opendest "set"
    openDest = 1
    wait
[noOpenDest]
    #pick.opendest "reset"
    wait
[yesShow]
    show = 1
    wait
[noShow]
    show = 0
    wait
[project]
    project = 1
    wait
[noproject]
    project = 0
    wait
[yesTKN]
    tkn = 0
    wait
[noTKN]
    tkn = 1
    wait
[yesBAS]
    bas=0
    wait
[noBAS]
    bas = 1
    wait
    ' passworded exe is true(user selected)
[yespass]
    p = 1
    wait
    'passworded exe is false, default
[nopass]
    p = 0
    wait
    'make 32 bit exe = true(user selected)
[bit32]
    bit=32
    #pick.bit64, "reset" : #pick.bit64 "hide"
    wait
    'make 64 bit exe, default
[bit64]
    bit=64
    #pick.bit32, "reset" : #pick.bit32 "hide"
    wait
[nobit32]
    bit=64
    #pick.bit64, "show" : #pick.bit32 "hide"
    wait
[nobit64]
    bit=32
    #pick.bit32, "show" : #pick.bit64 "hide"
    wait
    'append date/time to backed up tkn, and bas files - defaults to true
[appDT]
    dt = 1
    wait
[noappDT]
    dt = 0
    wait
[appVersion]
    #pick.versionText "!show"
    #pick.ve "!show" : #pick.ve "!setfocus"
    ve = 1
    wait
[noappVersion]
    #pick.ve ""
    #pick.versionText "!hide"
    #pick.ve "!hide"
    ve = 0
    wait
[yesLBB]
    if fileExists(DefaultDir$, "LBB.exe") = 0 then
        confirm "You will need the LB Booster Executable File"+chr$(13)+chr$(13)+"Download LBB.exe Now?";answer$
        If answer$<>"yes" then #pick.LBB "reset" : wait
        cursor hourglass
        run "curl -O https://lbbooster.com/LBB.exe",hide
        WindowWidth = 250:WindowHeight = 53
        UpperLeftX= int((DisplayWidth-WindowWidth)/2)
        UpperLeftY= int((DisplayHeight-DisplayHeight))+155
        statictext #down.text, "Downloading LBB.exe", 30,20,240,20
        open "Downloading LBB.exe" for window_popup as #down
        #down "font arial_14 bold"
        #down.text "Downloading LBB.exe"
        downOpen=1
        counter=0
        do
        counter=counter+1
        if counter>50000 then exit do
        loop until fileExists(DefaultDir$, "LBB.exe")
        if fileExists(DefaultDir$, "LBB.exe") = 0 then
            notice "LBB.exe was NOT Downloaded";chr$(13);chr$(13);"Restart BAS2EXE and Try Again"
            close #down
            close #pick
            downOpen=0
            end
        end if
        call pause 300
        if downOpen=1 then close #down :downOpen=0
        cursor normal
    end if
    #pick.LBB "set"
    LBB =1
    wait
[noLBB]
    #pick.LBB "reset"
    LBB = 0
    wait
[forumLink]
    run "explorer https://libertybasiccom.proboards.com/"
    wait

[defaultClick]
    if ve = 1 then #pick.ve "!contents? ve$" : ve$ = "-";ve$

[commandPath]
    'close the opening window for Selecting bas file
    if pickOpen = 1 then close #pick : pickOpen = 0
    'check existence and LBpath$ (Liberty Basic default install dir)
    if pathExists(LBpath$) = 0 then notice " Liberty Basic v4.5.1 was not was not found in ";LBpath$;" Restart BAS2EXE - Try Again" : end

    'define some variables
    LBexe$ = "liberty.exe"
    LBruntime$ = "run451.exe"
    supportFileList$="run451.exe vbas31w.sll vgui31w.sll voflr31w.sll vthk31w.dll vtk1631w.dll vtk3231w.dll vvm31w.dll vvmt31w.dll"
    projects$ = "b2eProjects"

    'make sure the support files exist
    fileCount = 0
    while 1
        fileCount = fileCount + 1
        runtimeSupportFile$ = word$(supportFileList$, fileCount)
        if runtimeSupportFile$ = "" then exit while
        if fileExists(LBpath$,runtimeSupportFile$) = 0 then notice "File doesn't Exist";chr$(13);LBpath$;"\";runtimeSupportFile$;chr$(13);"BAS2EXE will now Close" : end
    wend

    if command = 1 then [commandByPass]

    ' Use the filedialog function to allow user to select a source file (.bas)
[filediag]
    filedialog "Open a Liberty Basic Source File (.bas) ", "*.bas", fname$
    '  if instr(fname$, DefaultDir$) then notice chr$(13);"Selecting a File from within ";chr$(13);chr$(13);DefaultDir$;chr$(13);chr$(13);" is NOT ALLOWED";chr$(13);chr$(13);"Try Again With a Different File" : end
    if fname$ = "" then notice "No file selected, BAS2EXE will now close" : end

[commandByPass]
    if p = 1 then
        Prompt "TYPE a PASSWORD"+chr$(13)+ "Password For Your EXE File is? : (no spaces)";passwerd$
        if passwerd$ = "" then p = 0 : notice "BAS2EXE will continue, without placing a password on the EXE file created"
    end if
    'Separate path from selected filename, and extension from selected filename
    for var1 = len(fname$) to 1 step -1
        if mid$(fname$, var1, 1) = "\" then var2 = var1 -1 : var3 = var2 - ((len(fname$))) : exit for
    next var1
    var3 = abs(var3)
    orig$ = left$(fname$, var2)
    fname0$ = right$(fname$, var3 -1)
    for var4 = len(fname0$) to 1 step -1
        if mid$(fname0$, var4, 1) = "." then var5 = var4 -1 : var6 = var5 - ((len(fname0$))) : exit for
    next var4
    var6 = abs(var6)
    fnamenobas$ = left$(fname0$, var5)
    ' fname$ = Full Path of User Selected .bas file (including the filename.bas)
    ' fname0$ = Name of the Selected .bas File Only - eg ; filename.bas
    ' fnamenobas$ = Name of the Selected .bas File (without the .bas) - eg: filename

[begin]
    'define Destpath1$ as JB Projects\Current Project Folder
    DestPath$=DefaultDir$ 'Where this file is RUN from
    DestPathU$ = DestPath$;"\";projects$ 'Projects Folder
    DestPath1$=DestPathU$;"\";fnamenobas$ 'Current Project Folder

    'Make Folders for Liberty Basic Projects, EXE files, TKN files, BAS files, SED files and Current Projects
    res = mkdir(DestPathU$) 'projects dir
    res = mkdir(DestPath1$) 'new project dir = name of selected bas file (no .bas) in Projects Dir
    res =mkdir(DefaultDir$;"\";"EXE") 'exe files saved here
    res = mkdir(DefaultDir$;"\";"TKN") 'tkn files saved here
    res= mkdir(DefaultDir$;"\";"BAS")  'selected bas file saved here (includes password code if exe was passworded)

    'make sure Folders were actually created
    if pathExists(DestPathU$) = 0 then notice "Projects folder was NOT Created in ";DestPath$ : end
    if pathExists(DestPath1$) = 0 then notice "New Folder ";fnamenobas$;" was NOT Created in ";DestPath1$ : end
    if pathExists(DefaultDir$;"\";"TKN") = 0 then notice "TKN Folder was NOT Created in ";DestPath$ : end
    if pathExists(DefaultDir$;"\";"BAS") = 0 then notice "BAS Folder was NOT Created in ";DestPath$ : end
    if pathExists(DefaultDir$;"\";"EXE")  = 0 then notice "EXE Folder was NOT Created in ";DestPath$ : end
    'copy selected bas file to Projects\current project folder
    q$= chr$(34)
    open fname$ for input as #fname
    fnameTemp$="tempBas.bas"
    open fnameTemp$ for output as #2

    'add a password prompt to the begining of the temp bas file(to be added to the exe)
    if p=0 then [nopasswerd] '
    #2, "prompt ";q$;"Enter the Password to Run";q$;";";"passwerd$"
    #2, "if passwerd$ <> ";q$;passwerd$;q$;" then end"
[nopasswerd]
    #2, input$(#fname, lof(#fname));
    close #fname
    close #2

    'copy temp.bas file to current project folder
    open fnameTemp$ for input as #fnameTemp
    open DestPath1$;"\";fname0$ for output as #1
    #1, input$(#fnameTemp, lof(#fnameTemp));
    close #1
    close #fnameTemp
    if fileExists(DefaultDir$, fnameTemp$) then kill fnameTemp$
    'check if the current project .bas file was copied to new dir
    if fileExists(DestPath1$,fname0$) = 0 then notice fname0$; " Was not copied to  ";DestPath1$;" BAS2EXE will now close" : end
    'activity message to user - please wait message
    if quiet = 0 then gosub [pleasewait]

    'Check paths and file locations for existence (dll's, sll's, jbasic.exe, and jbrun2.exe)
    if fileExists(LBpath$, LBexe$) = 0 then notice " jbasic.exe Does not exist in  ";LBpath$;" Closing BAS2EXE":end
    if fileExists(LBpath$,LBruntime$) = 0 then notice " jbrun2.exe Does not exist in  ";LBpath$;" Closing BAS2EXE" : end
    if fileExists(LBpath$,"vvmt31w.dll") = 0 then notice " vvmt31w.dll Does not exist in  ";LBpath$;" Closing BAS2EXE" : end
    if fileExists(LBpath$,"vvm31w.dll") = 0 then notice " vvm31w.dll Does not exist in  ";LBpath$;" Closing BAS2EXE" : end
    if fileExists(LBpath$,"vtk3231w.dll") = 0 then notice " vtk3231w.dll Does not exist in  ";LBpath$;" Closing BAS2EXE" : end
    if fileExists(LBpath$,"vtk1631w.dll") = 0 then notice " vtk1631w.dll Does not exist in  ";LBpath$;" Closing BAS2EXE" : end
    if fileExists(LBpath$,"vthk31w.dll") = 0 then notice " vthk31w.dll Does not exist in  ";LBpath$;" Closing BAS2EXE" : end
    if fileExists(LBpath$,"voflr31w.sll") = 0 then notice " voflr31w.sll Does not exist in  ";LBpath$;" Closing BAS2EXE" : end
    if fileExists(LBpath$,"vgui31w.sll") = 0 then notice " vgui31w.sll Does not exist in  ";LBpath$;" Closing BAS2EXE" : end
    if fileExists(LBpath$,"vbas31w.sll") = 0 then notice " vbas31w.sll Does not exist in  ";LBpath$;" Closing BAS2EXE" : end

    'Copy the needed DLL and SLL files from Liberty Basic dir to projects\projectname Dir
    w$ = ""
    i = 0
    while 1
        i = i + 1
        w$=word$(supportFileList$, i)
        if w$="" then exit while
        from$=LBpath$;"\";w$
        to$=DestPath1$;"\";w$
        if fileExists(DestPath1$,w$) then [noneed]
        open from$ for input as #file
        open to$ for output as #1
        print #1, input$(#file, lof(#file));
        close #file
        close #1
[noneed]
    wend

    'remove existing jbrun2.exe from new project before creating new one
    if fileExists(DestPath1$, LBruntime$) then kill DestPath1$;"\"; LBruntime$

    'copy jbrun2.exe to current project Folder
    open LBpath$;"\";LBruntime$ for input as #file
    open DestPath1$;"\";LBruntime$ for output as #1
    print #1, input$(#file, lof(#file));
    close #file
    close #1

    'Liberty Basic can't create\rename a file that exists, so if it does already exist - kill it (delete it)
    if fileExists(DestPath1$, fnamenobas$ + ".exe") then kill DestPath1$;"\";fnamenobas$ + ".exe"
    'rename jbrun2.exe to name of User Selected .bas File - .bas +.exe
    name DestPath1$;"\";LBruntime$ as DestPath1$;"\";fnamenobas$ + ".exe"
    'check new exe (renamed run451.exe) file for existence in current project Folder )
    if fileExists(DestPath1$,fnamenobas$;".exe") = 0 then notice "run451.exe not copied or renamed - EXITING Program":  end
    'remove any existing exe from projectdir - of same name as bas file selected only if created on same date at same time
    if fileExists(DestPath$;"\EXE",fnamenobas$;".exe") then kill DestPath$;"\EXE\";fnamenobas$;".exe"
    'check for old tkn existence, delete if true
    if fileExists(DestPath1$,fnamenobas$;".tkn") then kill DestPath1$;"\";fnamenobas$;".tkn"

    gosub [makeSED]
    'verify sed file existence before proceeding
    do
    scan
    loop until fileExists(DestPath$,fnamenobas$;".sed")

    call writeAutoSave
    'loop until autoSave$ File is verified
    while fileExists(DefaultDir$, autoSave$) = 0 : scan : wend

    '#######################################################################
    'run the script to close the "save" dialog, and the follow up notice of creation automatically
    run "wscript  ";autoSave$
    '#######################################################################
    'Create the TKN file in Projects\current project folder.
    run LBpath$;"\";LBexe$;" -T -A ";DestPath1$;"\";fname0$
    '#######################################################################

    'loop until TKN File is verified saved
    do
    scan
    loop until fileExists(DestPath1$, fnamenobas$;".tkn")

    call fixtime : call fixdate ' append date/time to backup .bas and .tkn filename

    'copy selected .bas file to BAS dir and date it
    if bas = 1 then
        open fname$ for input as #file
        open DefaultDir$;"\BAS\";fnamenobas$;ve$;fixedDate$;fixedTime$;".bas" for output as #1
        print #1, input$(#file, lof(#file));
        close #file
        close #1
    end if

    ' allow JB code to catch up with TKN creation
    call pause 5500
    ' copy TKN$ file to TKN dir, and append date\time to it's name
    if tkn = 1 and fileExists(DestPath1$, fnamenobas$;".tkn") <> 0 then
        open DestPath1$;"\";fnamenobas$;".tkn" for input as #file
        open DefaultDir$;"\TKN\";fnamenobas$;ve$;fixedDate$;fixedTime$;".tkn" for output as #1
        print #1, input$(#file, lof(#file));
        close #file
        close #1
    end if
    fixedDate$ = "" : fixedTime$ = ""

    'First Run setup in User Home Dir for CommandLine use
    if command = 1 and firstRun = 1 then
        run "cmd.exe /c xcopy ";DestPath1$;" ";upath$;" /e /s /c /h /i /y", hide
        call pause 1000
        call wDS
        run upath$;"\b2e.exe"
    end if
    if firstRun = 1 then end

    if LBB = 1 then [LBB_EXE] 'make LB Booster EXE Instead of IEXPRESS EXE

    'Check if iexpress.exe is installed (a built in Windows Install Maker = Self Extracting exe File)
[makeinst]
    if fileExists("c:\windows\system32","iexpress.exe") then [makeexe] else notice "Cannot find file --> iexpress.exe in c:\windows\system32"+chr$(13)+"Known issue for users of WINE in Linux"+chr$(13)+"Check WINE Tricks for Adding IExpress(after each update)"

[makeexe]
    'makes 64 bit exe
    if bit=32 then [do32bit]
    'run iexpress commandline using the sed file created (sort of like an ini file)
    express64$ = "C:\Windows\System32"
    if fileExists(express64$,"iexpress.exe") then
        run "iexpress /N /q ";sedfile$ : goto [verifyEXE]
    else
        noie = 1 : goto [quit.main]
    end if
    'makes 32 bit exe
[do32bit]
    express32$ = "C:\Windows\SysWOW64"
    if fileExists(express32$,"iexpress.exe") then
        run "iexpress /N /q ";sedfile$ : print "IEXPRESS running 64BIT"
    else
        noie = 2 : goto [quit.main]
    end if
[verifyEXE]
    if command = 1 then
        do
        countTime = countTime + 1
        if countTime > 80000 then exit do '- In case of unreported error - EXE file verification loop exit
        scan
        loop until fileExists(exeDest$, exe$)
    end if
    'verify the exe file was created loop until it exists
    if command = 0 then
        do
        countTime = countTime + 1
        if countTime > 80000 then exit do '- In case of unreported error - EXE file verification loop exit
        scan
        loop until fileExists(DefaultDir$;"\EXE\", exe$)
    end if

    call pause 5500
    if dt = 1 then call fixdate : call fixtime

    ' append version, date, time to filename if selected
    if command = 1 then
        if fileExists(exeDest$, fnamenobas$;".exe") then exefilename$ = fnamenobas$;ve$;fixedDate$;fixedTime$;".exe"
        name exeDest$;"\";fnamenobas$;".exe" as exeDest$;"\";exefilename$
    end if
    if command <> 1 then
        if fileExists(DefaultDir$;"\EXE", fnamenobas$;".exe") then exefilename$ = fnamenobas$;ve$;fixedDate$;fixedTime$;".exe"
        name DefaultDir$;"\EXE\";fnamenobas$;".exe" as DefaultDir$;"\EXE\";exefilename$
    end if
    if runEXE = 1 and command = 1 and fileExists(exeDest$, exefilename$) then run exeDest$;"\";exefilename$
    call pause 1000
    if command = 0 and openDest = 1 then run "cmd.exe /c explorer /select, ";q$;DefaultDir$;"\EXE\";exefilename$;q$, hide' : goto [quit.main]
    if command = 1 and openDest = 1 then run "cmd.exe /c explorer /select, ";q$;exeDest$;"\";exefilename$;q$, hide : goto [quit.main]
    if show <> 1 then [quit.main]
    close #pleasewait : pleaseOpen = 0
[main]
    call pause 500
    'create a window with options to view created files or run the new exe file.
    WindowWidth = 400
    WindowHeight = 320
    UpperLeftX=INT((DisplayWidth-WindowWidth)/2)
    UpperLeftY=INT((DisplayHeight-WindowHeight)/2)
    BackgroundColor$ = "darkgray"
    ForegroundColor$ = "black"
    button #main.default, "Make  New  Single  EXE  File  (GUI Mode)", [rerun],UL 90, 200, 220, 40
    button #main.run, "Run  the  Created  EXE  File", [progrun],UL 125, 150, 150, 40
    button #main.browseT, "View  TKN  Files", [browseT],UL 125, 15, 150, 25
    button #main.browseB "View  BAS  Files", [browseB],UL 125, 45, 150, 25
    button #main.browseE, "View  EXE  Files", [browseE],UL 125, 75, 150, 25
    button #main.browseP, "View  Projects", [browseP],UL 125, 105, 150, 25
    button #main.jbforums, "For more Information > Click Here to Visit the Liberty Basic Forums", [forumLink], UL 0, 270, 400, 20
    open "View Files\ Run Created EXE \ Make New EXE" for dialog as #main
    #main, "trapclose [quit.main]"
    cursor normal
    mainOpen = 1
    wait
    'Make another EXE file
[rerun]
    if command = 1 then CommandLine$ = "" : exeDest$ = "" : fname$ = "" : command = 0
    goto [TOP]
    'open Windows explorer to the EXE Files
[browseE]
    if command = 1 and exeDest$ <> "" then run "explorer.exe ";exeDest$
    if command = 0  then run "explorer.exe ";DefaultDir$;"\EXE"
    wait
    'open Windows explorer to the backup TKN Files Files
[browseT]
    run "explorer.exe ";DefaultDir$;"\TKN"
    wait
    'open Windows explorer to the backup BAS Files
[browseB]
    run "explorer.exe ";DefaultDir$;"\BAS"
    wait
    'open Windows explorer to the Projects Dir
[browseP]
    run "explorer.exe ";DefaultDir$;"\b2eProjects"
    wait
    'Run the new CommandLine created exe file chosen
[progrun]
    if command = 1 then
        run exeDest$;"\";exefilename$
    end if
    if command = 0 then
        run DestPath$;"\EXE\";exefilename$
    end if
    wait

[quit.main]
    ' Delete .vbs file temp .txt and temp .bas files
    if fileExists(DefaultDir$, fnameTemp$) then kill fnameTemp$
    if fileExists(DefaultDir$,"temp.txt") then kill "temp.txt"
    if fileExists(DefaultDir$, "FolderDialog.vbs") then kill "FolderDialog.vbs"
    if fileExists(DefaultDir$, autoSave$) then kill autoSave$
    if fileExists(DefaultDir$,desktopShortcut$) then kill desktopShortcut$
    'if user chose to, - delete the current project dir and files (copied bas file, tkn file, sll,dll, jbrun2.exe(renamed file)
    if project = 0 then
        if fileExists(DestPath1$, "vbas31w.sll") then kill DestPath1$;"\";"vbas31w.sll"
        if fileExists(DestPath1$, "vgui31w.sll") then kill DestPath1$;"\";"vgui31w.sll"
        if fileExists(DestPath1$, "voflr31w.sll") then kill DestPath1$;"\";"voflr31w.sll"
        if fileExists(DestPath1$, "vtk1631w.dll") then kill DestPath1$;"\";"vtk1631w.dll"
        if fileExists(DestPath1$, "vthk31w.dll") then kill DestPath1$;"\";"vthk31w.dll"
        if fileExists(DestPath1$, "vtk3231w.dll") then kill DestPath1$;"\";"vtk3231w.dll"
        if fileExists(DestPath1$, "vvm31w.dll") then kill DestPath1$;"\";"vvm31w.dll"
        if fileExists(DestPath1$, "vvmt31w.dll") then kill DestPath1$;"\";"vvmt31w.dll"
        if fileExists(DestPath1$, exe$) then kill DestPath1$;"\";exe$
        if fileExists(DestPath1$, fnamenobas$;".tkn") then kill DestPath1$;"\";fnamenobas$;".tkn"
        if fileExists(DestPath1$, fnamenobas$;".bas") then kill DestPath1$;"\";fnamenobas$;".bas"
        if pathExists(DestPath1$) then deldir = rmdir(DestPath1$)
    end if
    if fileExists(DefaultDir$, fnamenobas$;".sed") then kill DefaultDir$;"\";fnamenobas$;".sed"
    if noie = 1 then notice "64Bit Version of IEXPRESS not installed"+chr$(13)+" No EXE File Created - BAS2EXE closing."
    if noie = 2 then notice "32Bit  Version of IEXPRESS not installed"+chr$(13)+" No EXE File Created - BAS2EXE closing."
    if pleaseOpen = 1 then close #pleasewait : pleaseOpen = 0
    if mainOpen = 1 then close #main : mainOpen = 0
    if pickOpen = 1 then close #pick : pickOpen = 0
    call pause 300
    if command = 1 and fileExists(exeDest$, exefilename$) = 0 then notice "Exe file was NOT created, check your syntax and try again"
    if command = 0 and fileExists(DefaultDir$;"\EXE\", exefilename$) = 0 then notice "Exe file was NOT created, check your syntax and try again"
    end

[quit.pleasewait]
    close #pleasewait
    wait

[cancel]
    close #pick
    end

[abort]
    notice "An error occured";chr$(13);"Error Code # ";Err;chr$(13);Err$;chr$(13);chr$(13);"BAS2EXE will Re-Start"
    if pleaseOpen = 1 then close #pleasewait : pleaseOpen = 0
    if mainOpen = 1 then close #main : mainOpen = 0
    if pickOpen = 1 then close #pick : pickOpen = 0
    if command = 0 then [TOP]
    goto [quit.main]

    '#######################################################################
    'make the sed file for iexpress to read and create the (Self Extracting Directorate) exe file
[makeSED]
    'can't write text to files that include quotes, so use the characters so they will print without syntax errors
    sedfile$=fnamenobas$;".sed"
    open sedfile$ for output as #sed
    #sed "[Version]"
    #sed "Class=IEXPRESS"
    #sed "SEDVersion=3"
    #sed "[Options]"
    #sed "PackagePurpose=InstallApp"
    #sed "ShowInstallProgramWindow=1"
    #sed "HideExtractAnimation=1"
    #sed "UseLongFileName=1"
    #sed "InsideCompressed=0"
    #sed "CAB_FixedSize=0"
    #sed "CAB_ResvCodeSigning=0"
    #sed "RebootMode=N"
    #sed "InstallPrompt=%InstallPrompt%"
    #sed "DisplayLicense=%DisplayLicense%"
    #sed "FinishMessage=%FinishMessage%"
    #sed "TargetName=%TargetName%"
    #sed "FriendlyName=%FriendlyName%"
    #sed "AppLaunched=%AppLaunched%"
    #sed "PostInstallCmd=%PostInstallCmd%"
    #sed "AdminQuietInstCmd=%AdminQuietInstCmd%"
    #sed "UserQuietInstCmd=%UserQuietInstCmd%"
    #sed "SourceFiles=SourceFiles"
    #sed "[Strings]"
    #sed "InstallPrompt="
    #sed "DisplayLicense="
    #sed "FinishMessage="
    exe$=fnamenobas$;".exe"
    if command = 1 and exeDest$ <> "" then
        #sed "TargetName=";q$;exeDest$;"\";exe$;q$
    else
        #sed "TargetName=";q$;DefaultDir$;"\EXE\";exe$;q$
    end if
    #sed "FriendlyName=";q$;fnamenobas$;q$
    #sed "AppLaunched=";q$;exe$;q$
    #sed "PostInstallCmd=<None>"
    #sed "AdminQuietInstCmd="
    #sed "UserQuietInstCmd="
    #sed "FILE0=";q$;exe$;q$
    sedtkn$=fnamenobas$;".tkn"
    #sed "FILE1=";q$;sedtkn$;q$
    sll1$="vbas31w.sll"
    sll2$="vgui31w.sll"
    sll3$="voflr31w.sll"
    dll1$="vthk31w.dll"
    dll2$="vtk1631w.dll"
    dll3$="vtk3231w.dll"
    dll4$="vvm31w.dll"
    dll5$="vvmt31w.dll"
    #sed "FILE2=";q$;sll1$;q$
    #sed "FILE3=";q$;sll2$;q$
    #sed "FILE4=";q$;sll3$;q$
    #sed "FILE5=";q$;dll1$;q$
    #sed "FILE6=";q$;dll2$;q$
    #sed "FILE7=";q$;dll3$;q$
    #sed "FILE8=";q$;dll4$;q$
    #sed "FILE9=";q$;dll5$;q$
    #sed "[SourceFiles]"
    #sed "SourceFiles0=";q$;DestPath1$;q$
    #sed "[SourceFiles0]"
    #sed "%FILE0%="
    #sed "%FILE1%="
    #sed "%FILE2%="
    #sed "%FILE3%="
    #sed "%FILE4%="
    #sed "%FILE5%="
    #sed "%FILE6%="
    #sed "%FILE7%="
    #sed "%FILE8%="
    #sed "%FILE9%="
    close #sed
    return

sub writeAutoSave
    q$ = chr$(34)
    autoSave$ = "autoSave.vbs"
    open autoSave$ for output as #1
    #1 "Set WshShell = WScript.CreateObject(";q$;"WScript.Shell";q$;")"
    #1, "Do While Not WshShell.AppActivate(";q$;"Save *.TKN File As...";q$;")"
    #1, "Loop"
    #1, "WshShell.SendKeys ";q$;"{ENTER}";q$
    #1, "Do While Not WshShell.AppActivate(";q$;"Information";q$;")"
    #1, "Loop"
    #1, "WshShell.SendKeys ";q$;"{ENTER}";q$
    #1, "Wscript.Sleep(100)"
    #1, "WshShell.AppActivate(";q$;"pleasewait";q$;")"
    close #1
end sub

sub fixdate
    fixDate$ = Date$() 'set up the date format that works with a filename(remove the /)
    fix1$ =word$(fixDate$, 1, " ")     ' = Month,
    fix2$ = word$(fixDate$, 2, " ")    ' = Month
    fix2$ = left$(fix2$, len(fix2$)-1)  ' = Number of day
    fix3$ = word$(fixDate$, 3 ," ")    ' = Year - 4 digits
    fix3$ = right$(fix3$, 2)                ' = Year - 2 digits
    fixedDate$ = "-";fix1$;"-";fix2$;"-";fix3$ ' = Month-NumberOfDay-Year
end sub

'editTime$() return for use in filenames
sub fixtime
    fixTime$ = Time$() 'set up the time format that works with a filename(remove the /)
    fix1$ = word$(fixTime$, 1, ":")' - remove the "." 's
    fix2$ = word$(fixTime$, 2 ,":")
    fixedTime$ = "-";fix1$;"-";fix2$  ' add dashes -
end sub

[pleasewait]
    WindowWidth = 450 : WindowHeight = 200
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)+50
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)+50
    statictext #pleasewait.text1, "     Please         Wait        While ", 50, 40, 325, 30
    statictext #pleasewait.text3, "BAS2EXE gets everything ready ", 70, 90, 325, 30
    statictext #pleasewait.text6, "This Can Take 10 - 20 Seconds ", 70, 140, 325, 30
    Open "pleasewait" for window_popup as #pleasewait
    #pleasewait "trapclose [quit.pleasewait]"
    #pleasewait "font verdana"
    pleaseOpen = 1
    return

    'write a vbs script to create a desktop shortcut to b2e.exe
sub wDS
    desktopShortcut$ = "desktopShortcut.vbs"
    open desktopShortcut$ for output as #1
    #1 "Set Shell = CreateObject(";q$;"WScript.Shell";q$;")"
    #1 "DesktopPath = Shell.SpecialFolders(";q$;"Desktop";q$;")"
    #1 "Set link = Shell.CreateShortcut(DesktopPath & ";q$;"\BAS2EXE.lnk";q$;")"
    #1 "link.Description = ";q$;"b2e shortcut";q$
    #1 "link.HotKey = ";q$;"CTRL+ALT+E";q$
    #1 "link.IconLocation = ";q$;"b2e.exe,0";q$
    #1 "link.TargetPath = ";q$;upath$;"\b2e.exe";q$
    #1 "link.WorkingDirectory = ";q$;upath$;q$
    #1 "link.Save"
    close #1
    run "wscript ";desktopShortcut$
end sub

'get users homepath = aka  %userprofile% = "c:\users\xxxxx" (5 characters long normally Win 10)
sub getUserPath
    run "cmd.exe /c echo %userprofile% >UserHomePath.txt", HIDE
    do
    scan
    loop until fileExists(DefaultDir$, "UserHomePath.txt")
    open "UserHomePath.txt" for input as #1
    upath$ = input$(#1, lof(#1))
    close #1
    if upath$ = "" then notice "Sorry, can't find user path " : end
    kill DefaultDir$;"\UserHomePath.txt"
end sub

'sub to create delays
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 for checking folder existence
function pathExists(path$)
    pathExists = (mkdir(path$)=183)
end function

'functions for making the folder dialog window
function FolderDialog$(caption$)
    WindowWidth = 600
    WindowHeight = 370
    UpperLeftX=INT((DisplayWidth-WindowWidth)/2)
    UpperLeftY=INT((DisplayHeight-WindowHeight)/2)
    BackgroundColor$ = "lightgray"
    ForegroundColor$ = "black"
    gosub [FolderDlgGetDrives]
    statictext #folderdlg.S, "Note: - Only Drives and Folders Appear Below - No Files Appear", 45, 15, 550, 25
    statictext #folderdlg.S, "Select a Drive or a Folder From the List", 175, 40, 300, 25
    statictext #folderdlg.D, "      (Double Click Drive Letters and Folders to Select or Navigate)", 85, 70, 395, 15
    listbox #folderdlg.list, FolderList$(, [FolderDlgSelect], 22, 90, 550, 130
    button #folderdlg.default, "Ok", [FolderDlgOk], UL, 190, 293, 85, 35
    button #folderdlg.B, "Back", [FolderDlgBack], UL, 490, 45, 80, 30
    button #folderdlg.C, "Cancel", [FolderDlgCancel], UL, 290, 293, 85, 35
    textbox #folderdlg.text, 42, 225, 510, 30
    statictext #folderdlg.path, "Selected Drive or Folder Path Appears Here", 130, 258, 400, 20
    open caption$ for dialog_modal as #folderdlg
    #folderdlg, "trapclose [FolderDlgCancel]"
    #folderdlg.default, "!font Arial 8 bold"
    #folderdlg, "font Arial 10 bold"
    #folderdlg.S, "!font Arial 10 bold"
    #folderdlg.path, "!font Arial 10 bold"
    #folderdlg.list, "font Arial 10 bold"
    #folderdlg.C, "!font Arial 10 bold"
    #folderdlg.D, "!font Arial 8 bold"
    #folderdlg.text, "!font Arial 10 bold"
    #folderdlg.list "singleclickselect"
    wait
[FolderDlgSelect]
    #folderdlg.list, "selection? temp$"
    if temp$ <> "" then
        level = level+1
        folder$ = folder$; temp$; "\"
        #folderdlg.text, folder$
        gosub [FolderDlgGetDir]
        #folderdlg.list, "reload"
    end if
    wait
[FolderDlgBack]
    if level > 0 then
        level = level-1
        if level = 0 then
            folder$ = ""
            gosub [FolderDlgGetDrives]
        else
            i = len(folder$)-1
            while mid$(folder$, i, 1) <> "\" and mid$(folder$, i, 1) <> ""
                i = i-1
            wend
            folder$ = left$(folder$, i)
            gosub [FolderDlgGetDir]
        end if
        #folderdlg.text, folder$
        #folderdlg.list, "reload"
    end if
    wait
[FolderDlgGetDrives]
    c = 1
    while word$(Drives$, c) <> ""
        c = c+1
    wend
    redim FolderList$(c)
    for i = 1 to c
        FolderList$(i) = word$(Drives$, i)
    next i
    return
[FolderDlgGetDir]
    files folder$, info$(
    s = val(info$(0,0))
    t = val(info$(0,1))
    redim FolderList$(t)
    for i = 1 to t
        FolderList$(i) = info$(i+s, 1)
    next i
    return
[FolderDlgOk]
    #folderdlg.text, "!contents? FolderDialog$"
    If right$(FolderDialog$,1) = "\" then FolderDialog$ = left$(FolderDialog$, len(FolderDialog$) - 1)
[FolderDlgCancel]
    close #folderdlg
end function

[LBB_EXE]
    LBB=0
    cursor hourglass
    LBB$ = DefaultDir$;"\LBB.exe"
    fname0$ = GetFilename$(fname$)
    open fname$ for input as #1
    open "EXE\";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$;"\EXE\";fname0$
    selected$ = left$(fname0$, len(fname0$)-4)
    do
    scan
    loop until fileExists(DefaultDir$;"\EXE", selected$;".exe")
    do
    scan
    loop until fileExists(DefaultDir$;"\EXE", selected$;".exe")
    if fileExists(DefaultDir$;"\EXE", selected$;".exe") then [verifyEXE] else notice "EXE File not Created" : end
    goto [verifyEXE]

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 to separate filename.ext 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