Post by xxgeek on Dec 28, 2020 20:48:22 GMT
Is there a way to convert a .bas file into a .tkn file without using the built in link in the "Run" menu?
I'm trying to do it in a batch file, but haven't figured out the format.
Is it text to asci, or text to binary, or hex?
Anyone know of a method?
[EDIT] - Since my question was answered I've worked to improve the code linked to by tsh73.
It's not perfect yet, but worth posting.
It works, and a user can automatically create the TKN file, copy the DLL's/SLL's and rename the runtime file while placing all the files into c:\Users\USERNAME\Application Data\Just Basic v2.0\Projects\"THE-USERS-Filename\PROJECTNAME.EXE, then it runs the PROJECTNAME.exe to show it exists
The user still needs to create the Projects directory before running this code, and to have a look at the paths in the top few lines . I have provided the Windows 10 most likely path for those who need it, just uncomment it
'attempt at making EXE programmatically
'tsh73 Jan 2019
'edited by xxgeek Dec 31 2020
'CHECK THE BELOW PATHS AND FILES - EDIT TO MATCH YOUR OWN ENVIRONMENT
'This program will not work unless you do this.
LBpath$="C:\Program Files (x86)\Just BASIC v2.0"' - May be "Program Files" for some users
LBexe$="jbasic.exe"
LBruntime$="jbrun2.exe"
DllList$="vbas31w.sll vgui31w.sll voflr31w.sll vthk31w.dll vtk1631w.dll vtk3231w.dll vvm31w.dll vvmt31w.dll"
orig$="C:\users\YOUR USER-NAME HERE\Application Data\Just BASIC v2.0"
tkn$ = "C:\users\YOUR USER-NAME HERE\Application Data\Just BASIC v2.0DestPath1$fname\"
' #######################################################
'Don't forget to put YOUR USER-NAME in where stated in the above/below few lines
Fullpath$ = "C:\users\YOUR USER-NAME HERE\Application Data\Just BASIC v2.0\Projects"
DestPath$="C:\users\YOUR USER-NAME HERE\Application Data\Just BASIC v2.0\Projects"
'# MUST CREATE PROJECTS FOLDER YOUR SELF BEFORE RUNNING THIS PROGRAM
' ---- For Windows10 users
'orig$="C:\users\YOUR USER-NAME HERE\App Data\Roaming\Just BASIC v2.0"
'tkn$ = "C:\users\YOUR USER-NAME HERE\App Data\Roaming\Just BASIC v2.0DestPath1$fname\"
'Fullpath$ = "C:\users\YOUR USER-NAME HERE\App Data\Roaming\Just BASIC v2.0\Projects"
'DestPath$="C:\users\YOUR USER-NAME HERE\App Data\Roaming\Just BASIC v2.0\Projects"
' #######################################################
qq$=chr$(34) '(")
ok=1
'Checking all file location for existing files
res=pathExists(LBpath$)
if res then print " exists" else print " Does not exist - ";LBpath$
ok=ok and res
res=fileExists(LBpath$,LBexe$)
if res then print " exists" else print " Does not exist - ";LBpath$,LBexe$
ok=ok and res
res=fileExists(LBpath$,LBruntime$)
if res then print " exists" else print " Does not exist - ";LBpath$,LBruntime$
ok=ok and res
res=pathExists(DestPath$)
if res then print " exists" else print " Does not exist - ";DestPath$
ok=ok and res
if not(ok) then
print "-----------------------"
print "Program Aborted - Check your files/folders and Paths!"
end
end if
'User names their project the name of their .BAS file
input "Enter Your Project Name (no extension):";fname$
'Trim any extension the user rmay have added by mistake.
fname0$=trim$(fname$)
fname$=fname0$
if right$(lower$(fname$),4)<>".bas" then fname$=fname$+".bas"
DestPath1$=DestPath$;"\";fname0$
'Check if user removed any old Project Name the samer.
result = mkdir(DestPath1$)
'Give user a scolding if they forgot!!
if result = 183 then
print "-----------------------"
print "Directory ";DestPath1$;" for your Project Name already exists"
print "Delete it, rename it or change Your Projects .bas filename"
end
end if
if result <> 0 then
print "-----------------------"
print "Directory for a project "
print " ";DestPath1$
print "not created - check your filename"
end
end if
'######################################
'Here is where we copy your "project name.BAS"
'To a newfile and then feed it to fname$
open orig$;"\";fname$ for input as #orig
open DestPath1$;"\";fname$ for output as #1
print #1, input$(#orig, lof(#orig));
close #orig
close #1
'######################################
'Wait while the above copying finishes up.
call pause 400
' - Uncomment to see if your .bas file loads into notepad
'run "notepad.exe ";DestPath1$;"\";fname$
'LBpath$ = "C:\Program Files (x86)\Just BASIC v2.0"
'#####################################
'Create the TKN file. A good time to cross your fingers :D
RUN LBpath$;"\";LBexe$;" -T -A ";DestPath1$;"\";fname$
'###################################
#
'User may need to increase this value for large BAS files.
call pause 2000
input "User can Press ENTER once this message appears";dummy$
'Check if TKN file was created in the right folder.
res=fileExists(DestPath1$,fname0$;".tkn")
if res then print " exists" else print " The TKN file was not created - no exist"
ok=ok and res
'No TKN = No Soup for You :D
if not(ok) then
print "----------------------------------------------------------------------------------"
print "TKN creation failed"
print "Re-Read this file to see where you went wrong"
print "One or more of your paths are incorrect - See Top of Code for paths"
print "----------------------------------------------------------------------------------"
end
end if
'Copy dll's, sll's, and jbrun2.exe to the Project folder
from$=LBpath$;"\";LBruntime$
to$=DestPath1$;"\";fname0$;".exe"
run "cmd.exe /c copy ";qq$;from$;qq$;" ";qq$;to$;qq$
run "cmd.exe /c copy ";"from$";" ";"to$"
'Give time for the copying
call pause 400
'Tell user the bad news, and to check all their path statements
res=fileExists(DestPath1$,fname0$;".exe")
if res then print " exists" else print "The EXE file was not created - no exis - CHECK PATHS"
ok=ok and res
w$=""
i=0
while 1
i=i+1
w$=word$(DllList$,i)
if w$="" then exit while
from$=LBpath$;"\";w$
to$=DestPath1$;"\";w$
print ,to$
run "cmd.exe /c copy ";qq$;from$;qq$;" ";qq$;to$;qq$
wend
'run "explorer ";qq$;DestPath1$;qq$
'This runs the new Project to show it was created ok.
'Comment it out if you don't want it to run.
run DestPath1$;"\";fname0$;".exe"
sub pause mil
t=time$("ms")+mil
while time$("ms")<t
scan
wend
end sub
'Function to check paths and file sfor existance.
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 check paths for existance.
function pathExists(path$)
'if we need it exist anyway
'catch error "Directory already exists".
pathExists = (mkdir(path$)=183)
end function
Here is the original code from tsh73
'paths and filenames. Check them!
LBpath$="C:\Program Files\Just BASIC v2.0"
LBexe$="jbasic.exe"
LBruntime$="jbrun2.exe"
DestPath$="C:\WRK\JB\madeEXE"
DllList$="vbas31w.sll vgui31w.sll voflr31w.sll vthk31w.dll vtk1631w.dll vtk3231w.dll vvm31w.dll vvmt31w.dll"
qq$=chr$(34) '(")
'" -> ";qq$;"
print "Attempt at making EXE programmatically"
print " create BAS -> TKN -> EXE"
print
'0) check files/folders
print "0) Checking files/folders"
ok=1
print "LBpath$=",LBpath$
res=pathExists(LBpath$)
if res then print " exists" else print " not exists"
ok=ok and res
print "LBexe$=",LBexe$
res=fileExists(LBpath$,LBexe$)
if res then print " exists" else print " not exists"
ok=ok and res
print "LBruntime$=",LBruntime$
res=fileExists(LBpath$,LBruntime$)
if res then print " exists" else print " not exists"
ok=ok and res
print "DestPath$=",DestPath$
res=pathExists(DestPath$)
if res then print " exists" else print " not exists"
ok=ok and res
if not(ok) then
print "-----------------------"
print "program aborted - check your files/folders!"
end
end if
'1) create BAS file
print
print "1) Create BAS file"
input "Enter file name (no extension):";fname$
'fname$="hello"
fname0$=trim$(fname$) 'base name
fname$=fname0$
if right$(lower$(fname$),4)<>".bas" then fname$=fname$+".bas"
print "BAS file name: "
print, fname$
'make a directory for a project
DestPath1$=DestPath$;"\";fname0$
print "make a directory for a project: "
print, DestPath1$
'goto [copy]
result = mkdir(DestPath1$)
if result = 183 then
print "-----------------------"
print "Directory for a project "
print " ";DestPath1$
print "already exists - delete it or change your filename"
end
end if
if result <> 0 then
print "-----------------------"
print "Directory for a project "
print " ";DestPath1$
print "not created - check your filename"
end
end if
print "gathering data for BAS file..."
input "Enter window title:";ttl$
input "Enter message:";msg$
print
print "creating file ";fname$;"..."
' nomainwin
' notice "made EXE"+chr$(13)+"Hello there"
' end
open DestPath1$;"\";fname$ for output as #1
#1, "nomainwin"
#1, "notice "; qq$;ttl$;qq$; "+chr$(13)+"; qq$;msg$;qq$
#1, "end"
close #1
print "created BAS file: "
print, DestPath1$;"\";fname$
call pause 300
print "running file in Notepad (just close it)"
run "notepad.exe ";DestPath1$;"\";fname$
'2) create TKN file
print
print "2) Creating a TKN file"
print "this will leave SAVE TKN dialog"
print " *Just press ENTER* "
print "(and on Information box(es) press Ok too)"
'RUN "JBASIC -T -A PROG.BAS"
RUN LBpath$;"\";LBexe$;" -T -A ";DestPath1$;"\";fname$
'this leaves a dialog or two. If one pass ENTER there it will help.
'now, this file is AHK script pressing OK for you
call pause 2000 'may take a while
'RUN "saveTKNok.exe"
input "Press ENTER then ready";dummy$
print ,DestPath1$;"\";fname0$;".tkn"
res=fileExists(DestPath1$,fname0$;".tkn")
if res then print " exists" else print " not exists"
ok=ok and res
if not(ok) then
print "-----------------------"
print "TKN creation failed"
end
end if
[copy]
'3) copy files
print
print "3) Copy necessary files"
'runtime
print "runtime"
from$=LBpath$;"\";LBruntime$
to$=DestPath1$;"\";fname0$;".exe"
'run "cmd.exe /k echo ";qq$;from$;qq$;" ";qq$;to$;qq$
run "cmd.exe /c copy ";qq$;from$;qq$;" ";qq$;to$;qq$
call pause 300
print , to$
res=fileExists(DestPath1$,fname0$;".exe")
if res then print " exists" else print " not exists"
ok=ok and res
'dll sll
print "DLL / SLL"
w$=""
i=0
while 1
i=i+1
w$=word$(DllList$,i)
if w$="" then exit while
from$=LBpath$;"\";w$
to$=DestPath1$;"\";w$
print ,to$
run "cmd.exe /c copy ";qq$;from$;qq$;" ";qq$;to$;qq$
wend
print "Folder with project"
print DestPath1$
run "explorer ";qq$;DestPath1$;qq$
print "-=*over*=-"
'-----------------------------
sub pause mil
t=time$("ms")+mil
while time$("ms")<t
scan
wend
end sub
function fileExists(path$, filename$)
dim info$(0, 0)
files path$, filename$, info$()
fileExists = val(info$(0, 0)) 'non zero is true
end function
function pathExists(path$)
'if we need it exist anyway
'catch error "Directory already exists".
pathExists = (mkdir(path$)=183)
end function
[code]'Here is the editted code. Again lol, I can't seem to get it right, so I'll leave it instead of making it worse.
'attempt at making EXE programmatically
'tsh73 Jan 2019
'edited by xxgeek
'CHECK THE BELOW PATHS AND FILES - EDIT TO MATCH YOUR OWN ENVIRONMENT
'This program will not work unless you do this.
LBpath$="C:\Program Files (x86)\Just BASIC v2.0" 'May be C:\Program Files for some users
LBexe$="jbasic.exe"
LBruntime$="jbrun2.exe"
DllList$="vbas31w.sll vgui31w.sll voflr31w.sll vthk31w.dll vtk1631w.dll vtk3231w.dll vvm31w.dll vvmt31w.dll"
orig$="C:\users\YOUR USER-NAME HERE\Application Data\Just BASIC v2.0"
tkn$ = "C:\users\YOUR USER-NAME HERE\Application Data\Just BASIC v2.0\DestPath1\$fname\"
' #######################################################
'Don't forget to put YOUR USER-NAME in where stated in the above/below few lines
Fullpath$ = "C:\users\YOUR USER-NAME HERE\Application Data\Just BASIC v2.0\Projects"
DestPath$="C:\users\YOUR USER-NAME HERE\Application Data\Just BASIC v2.0\Projects"
'# MUST CREATE PROJECTS FOLDER YOUR SELF BEFORE RUNNING THIS PROGRAM #
' ---- For Windows10 users
'orig$="C:\users\YOUR USER-NAME HERE\App Data\Roaming\Just BASIC v2.0"
'tkn$ = "C:\users\YOUR USER-NAME HERE\App Data\Roaming\Just BASIC v2.0\$fname"
'Fullpath$ = "C:\users\YOUR USER-NAME HERE\App Data\Roaming\Just BASIC v2.0\Projects"
'DestPath$="C:\users\YOUR USER-NAME HERE\App Data\Roaming\Just BASIC v2.0\Projects"
' #######################################################
qq$=chr$(34) '(")
ok=1
'Checking all file location for existing files
res=pathExists(LBpath$)
if res then print " exists" else print " Does not exist - ";LBpath$
ok=ok and res
res=fileExists(LBpath$,LBexe$)
if res then print " exists" else print " Does not exist - ";LBpath$,LBexe$
ok=ok and res
res=fileExists(LBpath$,LBruntime$)
if res then print " exists" else print " Does not exist - ";LBpath$,LBruntime$
ok=ok and res
res=pathExists(DestPath$)
if res then print " exists" else print " Does not exist - ";DestPath$
ok=ok and res
if not(ok) then
print "-----------------------"
print "Program Aborted - Check your files/folders and Paths!"
end
end if
'User names their project the name of their .BAS file
input "Enter Your Project Name (no extension):";fname$
'Trim any extension the user rmay have added by mistake.
fname0$=trim$(fname$)
fname$=fname0$
if right$(lower$(fname$),4)<>".bas" then fname$=fname$+".bas"
DestPath1$=DestPath$;"\";fname0$
'Check if user removed any old Project Name the samer.
result = mkdir(DestPath1$)
'Give user a scolding if they forgot!!
if result = 183 then
print "-----------------------"
print "Directory ";DestPath1$;" for your Project Name already exists"
print "Delete it, rename it or change Your Projects .bas filename"
end
end if
if result <> 0 then
print "-----------------------"
print "Directory for a project "
print " ";DestPath1$
print "not created - check your filename"
end
end if
'######################################
'Here is where we copy your "project name.BAS"
'To a newfile and then feed it to fname$
open orig$;"\";fname$ for input as #orig
open DestPath1$;"\";fname$ for output as #1
print #1, input$(#orig, lof(#orig));
close #orig
close #1
'######################################
'Wait while the above copying finishes up.
call pause 400
' - Uncomment to see if your .bas file loads into notepad
'run "notepad.exe ";DestPath1$;"\";fname$
'LBpath$ = "C:\Program Files (x86)\Just BASIC v2.0"
'#####################################
'Create the TKN file. A good time to cross your fingers :D
RUN LBpath$;"\";LBexe$;" -T -A ";DestPath1$;"\";fname$
'###################################
#
'User may need to increase this value for large BAS files.
call pause 2000
input "User can Press ENTER once this message appears";dummy$
'Check if TKN file was created in the right folder.
res=fileExists(DestPath1$,fname0$;".tkn")
if res then print " exists" else print " The TKN file was not created - no exist"
ok=ok and res
'No TKN = No Soup for You :D
if not(ok) then
print "----------------------------------------------------------------------------------"
print "TKN creation failed"
print "Re-Read this file to see where you went wrong"
print "One or more of your paths are incorrect - See Top of Code for paths"
print "----------------------------------------------------------------------------------"
end
end if
'Copy dll's, sll's, and jbrun2.exe to the Project folder
from$=LBpath$;"\";LBruntime$
to$=DestPath1$;"\";fname0$;".exe"
run "cmd.exe /c copy ";qq$;from$;qq$;" ";qq$;to$;qq$
run "cmd.exe /c copy ";"from$";" ";"to$"
'Give time for the copying
call pause 400
'Tell user the bad news, and to check all their path statements
res=fileExists(DestPath1$,fname0$;".exe")
if res then print " exists" else print "The EXE file was not created - no exis - CHECK PATHS"
ok=ok and res
w$=""
i=0
while 1
i=i+1
w$=word$(DllList$,i)
if w$="" then exit while
from$=LBpath$;"\";w$
to$=DestPath1$;"\";w$
print ,to$
run "cmd.exe /c copy ";qq$;from$;qq$;" ";qq$;to$;qq$
wend
'run "explorer ";qq$;DestPath1$;qq$
'This runs the new Project to show it was created ok.
'Comment it out if you don't want it to run.
run DestPath1$;"\";fname0$;".exe"
sub pause mil
t=time$("ms")+mil
while time$("ms")<t
scan
wend
end sub
'Function to check paths and file sfor existance.
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 check paths for existance.
function pathExists(path$)
'if we need it exist anyway
'catch error "Directory already exists".
pathExists = (mkdir(path$)=183)
end function