A long time ago, in Small-town, USA, life was much simpler. A teen-age hot rodder or shade-tree mechanic could take a screw-driver, a pair of pliers, and a "knuckle-buster" (adjustable wrench) into the back yard, pop the hood on the family jitney, and perform anything short of a complete engine replacement. He could probably do that too, and wouldn't hesitate to attempt the task, but special tools might make it easier.
So it is with personal computers, programming in general, and programming in Just Basic specifically. When you write simple programs, such as "Guess a Number" or "EZ Calculator," you don't have to provide much information to the user. By adding common icons, most users will know how to start, make an entry, and quit, without needing help files.
As programs become more complicated, limited prompting can be made with STATICTEXT boxes. A larger program may require a text file to explain what the program is intended to do, what options are available, and what shortcuts are provided for common tasks. The simplest help files are text files you create with your word processor.
When applications become even larger, HTML and CHM files are used as help files. HTML help files are web pages displayed in your browser. They can easily be created using word pad (if you know HTML markup language), or you can use an HTML editor to produce web pages for you as easily as typing a word document. MS Word can be used to create web pages, including colors, links, and images. Simply prepare your help file and click on File, choose Save as Web Page, and an HTML file will be created for you.
If you create an HTML file for your program, you will have to include any images, sounds, or other supporting files with needed for the web page.
Another type of help file is the CHM, or compiled help file. This consists of one or more HTML files, images, and sounds, compiled as a single stand alone file. You must first create HTML files for your program, then compile them using an application such as MS Visual CHM, which can be downloaded free from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/htmlhelp/html/hwMicrosoftHTMLHelpDownloads.asp. See Alyce Watson's tutorial in Liberty NL#108 for examples using this Wizard. http://babek.info/libertybasicfiles/lbnews/nl108/chm.htm
Using Visual CHM is fairly simple, as explained in the newsletter. Alyce illustrates an API call to run a CHM file, which cannot be used in Just Basic, but she kindly provided me with a work around which can be used with JB.
Here is the code for this DEMO.
'Running Help Files with Just Basic
NOMAINWIN
WindowWidth=200
WindowHeight=150
UpperLeftX=INT((DisplayWidth-WindowWidth)/2)
UpperLeftY=INT((DisplayHeight-WindowHeight)/2)
STATICTEXT #w.stt, "Please click a button.", 20, 10, 160, 25
BUTTON #w.btn1, "TEXT", [txt], UL, 20, 50, 60, 25
BUTTON #w.btn2, "HTML", [htm], UL, 20, 90, 60, 25
BUTTON #w.btn3, "CHM", [chm], UL, 120, 50, 60, 25
BUTTON #w.btn4, "QUIT", [quit], UL, 120, 90, 60, 25
OPEN "Help Files" for Window as #w
PRINT #w, "trapclose [quit]"
PRINT #w.stt, "!font arial 12"
WAIT
[txt] 'Runs a text file.
RUN "notepad myHelp.txt"
WAIT
[htm] 'Runs an HTML file.
fileName$=DefaultDir$+"myHelp.htm"
RUN "C:Program FilesInternet Exploreriexplore.exe "+fileName$
WAIT
[chm] 'Runs a compiled help file.
RUN "hh myhelp.chm"
WAIT
[quit]
CLOSE #w
END
The above code should be fairly straight forward. Running a help file as a text document simply requires RUN "notepad myHelp.txt", where myHelp.txt is the name of the help file. NOTE the space within "notepad myHelp.txt". A "File not found" error will occur at runtime unless the help file is located within the same folder as the program, unless you provide the full path to the help file.
Running an HTML help file can sometimes be as simple as running the text file. RUN "explorer myHelp.htm" will usually open the browser and display the help file, but not always. Just as the family jitney has computer chips, seat belts, and air bags to provide safety to the family, some firewalls protect you from spy ware and viruses by isolating your browser. Because you cannot be certain of the configuration of your user's computer, you may need a little more complicated code to run an HTML file.
fileName$=DefaultDir$+"myHelp.htm"
RUN "C:Program FilesInternet Exploreriexplore.exe "+fileName$
Failure to include the space following iexplore.exe will cause an error at runtime. The first line assigns the full path of myHelp.htm to variable fileName$ which is added to the RUN command to run the browser and help file. This code will work for the 87% of users with Internet Explorer. If they use a different operating system, or have removed Internet Explorer in favor of another browser, the user will receive a "File not found" error at runtime.
The last form of help file in this DEMO, is the CHM file. You create your help file in the same manner as an HTML help file, and then compile it to myHelp.chm (or whatever filename is appropriate for you). All users should be able to run a CHM file. Because we cannot make an API or DLL call with Just Basic, we run a windows file, hh.exe located in the WINDOWS folder, to open and display myHelp.chm.
RUN "hh myHelp.chm"
Adding help files to your programs not only makes them look more professional, they are easier to understand by the user and save a lot of programming space where you might otherwise need to display STATICTEXT.
When you are finished, you will have an attractive presentation which can be distributed to your friends to showcase the talents you have learned when writing programs with Just Basic.