Pursuit of the Graf STrivial
A practical teaching aid in GFA BASIC
By Patrick Bass, ST Resource Technical Editor
I was aghast. At the editorial meeting for this issue I was told I must actually write a practical program for the ST computer using GFA BASIC. I stumbled out of the meeting with sweat beading on my forehead like diamonds of fear. This time, I thought to myself, they were asking too much!
Help arrived, and in a most unusual way. Sitting on my desk was a letter from a woman in Saudi Arabia, asking for my help in finding a program. She teaches English there, and was looking for software that would automate the multiple-choice tests she gives. I starting writing, to tell her I didn't know of any, when the idea lightbulb went off over my head: Why not write it myself?
SHIFT INTO HIGH
The gears were turning in my pointed head. Practical program plus September issue plus GFA BASIC equals multiple choice quiz program which could be used for anything from a trivia quiz to a final exam.
In a nutshell, the ST program this month works like this: You can make up the quiz using a word processor, such as 1st Word, WordWriter, or MicroEmacs. The STRIVIA program can then read this quiz file, presenting the questions in a logical manner, and keep track of which questions were answered correctly, incorrectly, and also how long it took for each question to be answered.
The person taking the test selects the answer by either pressing the key with same number (1-5) or by using the mouse to click on the answer. Pressing or clicking on [RETURN] proceeds to the next question.
At the end of the test the results are either printed directly to the screen, or to a disk file for saving, as determined by the command line in the quiz file.
KEY IN THE LOCK
The key to this program is the format of the quiz file you create. It's both simple and powerful at the same time. As the program stands now, there is room for 500 questions, but feel free to bump that up to 5000 if need be. We've got lots of room left.
The format of the quiz file is actually very simple. Blank lines and REMark lines are ignored. REMark lines have an apostrophe (') or a semicolon (;) as the first character. Blank lines don't. You'll use REMark lines to help you keep track of which question is which.
The file needs to start out with a line for the header line, which will appear at the top of each question, and also on the test results printout. Up to ten lines will be accepted; however, only the first line will be displayed. The end of the set of header lines is marked with a single asterisk (*) on a line by itself.
Next, you may type up to three commands the program recognizes. They may all be on a single line, as in the example listing, or each on a separate line. The three commands are: Show, Delay, and Display.
The test-taking program will assume the commands are not active unless you "turn them on" here, by typing them in.
THE SHOW-ME STATE
The command Show will direct the program to tell the user whether the answer was correct or incorrect when the [RETURN] key is pressed. The command Delay must be followed by a number from 1 to 9999. This command determines how long the program will spend on each question before moving on to the next. The last command is Display, which will cause the computer to display the final test results onscreen. If display is not enabled, the program will write the test results to a disk file called "RESULTS".
After the commands line, there must be a line with a single number on it, telling exactly how many test questions there are. In our example file there are three questions.
Now come the questions themselves. The questions may be up to 15 lines of 40 characters each. Each question must end with a single asterisk(*) on a line by itself. After each question, type in five answers, one to a line, and each ending with a carriage return. You must signify the correct answer by placing a "greater-than" symbol (>) in front of it as the first character on the line.
And at this point the file format repeats: questions, answers, questions, answers, and so on, until the test is finished.
TYPING IT IN
While this program is written in GFA BASIC, you should be able to use it with ST BASIC without undue stress in conversion. Carefully type the program in and save a copy to disk before running it. GFA BASIC will not let you make a syntax mistake, but it is possible to misspell a variable name, so be careful. If you have the Antic Monthly Disk you'll find both the GFA BASIC source code and the compiled program version (along with the sample quiz) on side B as STRIVIA.BAS, STRIVIA.PRG, and STRIVIA.QIZ.
PROGRAM TAKE-APART
Let's examine the program in detail. The top few lines start with an asterisk; they're comments that tell who the programmer is and when he wrote it. We next @Initialize the program, and then repeatedly open a quiz file, take the test, and print the results. Before we can end an Alert Box will pop up, asking if we want to take another quiz. If we answer no, the program will end.
Initialize
This subroutine takes care of placing proper values inside variables. The Xbios(4) call returns the current resolution. Then the routine saves place for strings of questions and answers, and sets finished false, since we're not finished yet.
Open Quiz File
To embellish the drab old File Selector box, here we first put up some explanatory text around it, and then show the File Selector itself. The file we choose will be returned inside the variable Filename$. If the file actually does exist, the program opens it up to read from it, and drags all the header lines out. Then it clears the screen, and draws the paper and "Return" button on the screen. Next, it grabs a copy of the screen and places it inside new_page$.
Then, until it finds another asterisk in the file, it checks each line for a command, as described earlier. It gets the total number of questions, and returns from this subroutine.
Get Line
This short subroutine grabs an entire line from the disk, including punctuation. If the line starts with an apostrophe or semi-colon, or if the line is blank, it is discarded and another line is pulled from the file.
Take The Quiz
This subroutine really does all the work here. It starts off by resetting all the question variables to zero. Then it presents each question we know about onscreen and waits for an answer. It keeps track of the results by placing them inside an array, to be printed out when the test is finished.
TEACHERS OF THE WORLD UNITE
Don't look now, but you teachers out there can easily adapt this program for your own uses. All you need to change is the question file. Just think of the fun you'll have letting your ST give 3000-question tests, and then automatically grading them.