Introduction%This demo gives just a few ideas how to make a help page that resembles a compiled help file and uses an external txt document.

You may freely use code and ideas given in this demo in your programs.Help Window%In this demo a listbox is used for the table of contents, and a large plain statictext field displays the contents of the chapter. Statictext is placed inside a groupbox which is used to display the heading.

Following code was used to define the help window controls and fonts:

STATICTEXT #help.contents, "Contents:", 10, 20, 100, 20
LISTBOX #help.lb, topics$(), [newTopic], 10, 40, 200, 340
GROUPBOX #help.gb, "Heading", 216, 20, 320, 400
STATICTEXT #help.info, "Infofield", 224, 60, 310, 340
BUTTON #help, "Close", [closeHelp], UL, 60, 390, 80, 30
OPEN "Help" FOR window AS #help
#help, "trapclose [closeHelp]"
#help, "font ms_sans_serif 10"
#help.gb, "!font ms_sans_serif 14 bold"Trapping Help Open%A flag is used to see if the help window is open or closed. (The user of the program should always be able to consult the help page and this is why it's not a very good idea to make it a modal dialog window.)

In this demo helpOpen is the flag. If helpOpen = 0 then the window is not open, if helpOpen = 1 then it is.

This flag is evaluated/modified in four places:

1) when help window is opened, it is set to 1;
2) in the trapclose branch for the Help window, it is set to 0;
3) in the close branch of the main program, the flag is evaluated and help window closed if helpOpen = 1;
4) before opening the Help window this flag is also evaluated and opening is cancelled with WAIT if the Help window is already open.Scripting the Text File%The contents of the help file can be easiliy typed and edited with Notepad.

However, since we want to display the text as separate contents pages, it is a good idea to add a special symbol between topics/pages, that will be used as a word delimiter once we start parsing the file.

Another special symbol is used in each page to separate heading from body text.

For obvious reasons the delimiters used in this demo can't be shown, but you can look them up in the "helpText.txt" file.Reading TXT File%At the beginning of the program, the help file is opened and its full contents placed into a string. Then this string is parsed using the WORD$ function and the word delimiters of our choice to fill in two arrays: one for headings and one for topic contents.

(If the help system uses more than 10 pages you'll need to DIMension these arrays first.)

This code is used to get and interpret the file:

OPEN "helpText.txt" FOR INPUT AS #file
  helpText$ = INPUT$(#file, LOF(#file))
CLOSE #file
z = 1
WHILE WORD$(helpText$, z, pageDelimiter) <> ""
  a$ = WORD$(helpText$, z, pageDelimiter)
  topics$(z) = WORD$(a$, 1, headingDelimiter)
  pageText$(z) = WORD$(a$, 2, headingDelimiter)
  z = z+1
WENDHelp Page Display% Once the help text has been put into arrays, displaying the pages is a piece of cake. The trick is done by a listbox event that gets the topic number, and an Update branch that simply prints the chosen heading and body text to the groupbox and statictext respectively.

Just make sure something is displayed when the Help window is opened. You can also use a special variable for page numbers that doesn't get modified elsewhere in the program to open the Help window with the last viewed topic.

IF q = 0 THEN q = 1
[update]
#help.gb, topics$(q) : #help.info, pageText$(q)
WAIT

[newTopic]
#help.lb, "selectionindex? q"
IF q = 0 THEN WAIT
GOTO [update]Debugging and Polishing% After you have created the text file and programmed the viewer, it's time to test the results. Check all the pages and pay attention to the following:

- spelling;

- all pages fit into the Help window. If not, consider making the window and/or controls bigger, changing font size, making the text shorter, dividing text between two or more chapters etc;

- other possible bugs: e.g, the listbox array should not contain any line breaks because these are displayed as non-printing symbols; help text does not accidentally contain symbols that were used for word delimiters etc.Further Enhancements% You may also hard-code all help information in your program if you don't want to use an external file.

You may use different controls, e.g, TEXTEDITOR instead of the statictext field.

You may substitute the LISTBOX with a GRAPHICBOX to use bmp icons and even create a tree for subtopics.

You may also use a GRAPHICBOX for page contents and create an advanced scripting language for the text file to include text and image location data, that would enable also to display bmp images that come with the program.

You may add a Search/Index feature using a parsing routine that searches for keywords in the headings/topics array and lists matching pages, for example, in a COMBOBOX.

And anything else you may come up with! 
 
