Runtimes and All That

by Del

I don't know about you but when I have written a program I don't want to have to run the program through the editor. I want to be able to run it with Windows like a normal program.

I read the JB help file "Using the Run Time Engine". I originally read the file to mean that to make a standalone file you must rename a copy of jbrun101.exe to match your .tkn file. When it was patiently explained to me that I could run a .tkn file from within a JB program I decided to accept this as a mystery of JB.

Later I started to think about the whole business again. There are plenty of languages around like Java which need a runtime to run programs. What made JB different?

On my PC I put all my JB ".bas files in "My Documents" in the a folder called "Basic". In that folder is another folder "runtime". In "runtime" I have a copy of "jbrun101.exe called "picker.exe". All the other necessary files are also there.

Also in folder "runtime" is "picker.tkn", "calendar.tkn" and "run.bas" as well. "run.bas" must be the shortest file I have ever written.

It is


                	run "picker"
                	end

I expected from my knowledge of Windows and from the JB help file that the result would be that the program in "picker.tkn" would be run. I would point that "picker.exe" was found without any path details because "run.bas" was in DefaultDir$ with "picker.exe". Note that I have not made a mistake in the program. I deliberately left the suffix ".exe" off since it is not necessary.

I modified the program to


			run "picker calendar.tkn"
			end

I did not know what to expect this time but the "calendar.tkn" program ran. The ".tkn" file with the same name as the runtime is only run if no other ".tkn" file name is used. Just to make another point I changed run.bas to


			run "notepad"
			end

If this seems to be trivial remember that "notepad.exe" is in a completely different folder from "run.bas". It is in the folder "c:\windows\system32" which is in the PATH environmental variable. This means that all the ".exe" files in that path are "visible" in any folder on the PC. In principle the runtime could be put in that directory but it is probably better to leave the Windows folder untouched.

The next thing I tried was to put "run.bas" in the "basic" folder. I changed the file to


			run "runtime\picker runtime\picker.tkn"
			end

This program worked as I expected. There are several points to note. There is not a backslash before "runtime\picker" or "runtime\picker.tkn". This is called a relative path. "run.bas" is in the the "basic" folder and the "picker" folder is in "basic".

Another point is that I have had to put in a path for "picker.tkn". The reason is that when an executable file like "picker.exe" is called a copy of the code in the file is loaded into memory. The program is then run and it looks for a file in the same directory as "run.bas" or if you prefer "DefaultDir$". So you have to put in path details for "picker.tkn" as well. It is also worth noting that "picker.exe? is the name of a file on disk. You can load as many copies of the file into memory as you like and run them because Windows is multitasking.

I then changed the program yet again.


			run DefaultDir$; "\runtime\picker" ; " ";_
			 DefaultDir$; "\runtime\picker.tkn"
			end

This ran OK. DefaultDir$ contains the path to the current folder. 'DefaultDir$; "\picker\picker"' is the absolute path to "picker.exe" rather than the relative path. You must include the leading backslash in "\runtime\picker" or the file will not be found. I have no strong feelings about whether absolute or relative paths should paths should be used but it is probably safer to use the absolute path. There is one slight problem with DefaultDir$. It must be in the path to the required folder.

Finally


			run "c:\program files\just basic v1.01\jbrun101"; " ";_ 				  DefaultDir$;
"\picker\picker.tkn"
			end

Why not use "jbrun101.exe"? This also works.

You can also run programs directly from Windows. The principles are exactly the same. You can run any ".tkn" file using the same runtime file. This can be a bit of a fiddle. If you use the "run" option you can select the runtime using "browse". You then have to type the correct path to the ".tkn" file. You can also set up a shortcut which is also a fiddle but at least you only have to do it once.

By far the easiest method is to set up a file association. You can set up an association of the ".tkn" suffix with any copy of "jbrun101.exe".

Then you can run this


			run "picker\picker.tkn"
			end

I asked the question at the beginning "What made JB different". The short answer is very little. If you know your around the Windows file system there should be no problems.