So far, my spelling test program has been presenting the list of words contained in theTest in top to bottom order. I wanted to also be able to present the words in random order, so I've created an inorder flag with a value of 1 for presentation in order, or zero for random presentation, which works fine.
I start with the full set of words in theTest where each word is on one line. As a word is used in order from the top of the list, it is deleted from the list. Cycling through the list works fine from beginning to end.
For the random selection, I first started by using linesFN(theTest) to determine how many words remained in the list. Then I used that value as the maximum for the RndFN(1,wordsRemaining) to randomly pick a line number from the list. I was surprised when the program sometimes didn't present a word near the end of the test.
I inserted some code to compile a set of variable names and values to display for me using Message and found that theTest would lose a word, as well as a line, for each cycle - until the last cycle, at which time it would suddenly acquire a blank line at the end, which meant that linesFN(theTest) then returned a value that was one more than the actual number of words left, which should have been 1. It did return the correct number of lines, but the problem is that there was now an unwanted blank line that was being counted at the end of the variable.
My current fix is to instead use my wordCheck variable which is initially set to the total number of words (previously determined) and which is successively decremented as words/lines are deleted from the list.
The question is: why doesn't deleteLineVar theTest,wordLine remove the appropriate line from the list without adding a blank line when there will only be one word left in the list? This seems to me to be a BUG.
Below is the relevant portion of my code in which I have commented out the two lines below ELSE that didn't work. The line immediately below these two lines is the alternative that instead provides the expected results.
Global theTest,theWord,wordCheck,wordCount,wordTotal,inorder
Local wordsRemaining,wordLine
IF inorder=1 then
@ use top word from the working list IN ORDER
put line 1 of theTest into theWord
@ remove top word from the working list
deleteLineVar theTest,1
decrement wordCheck
@ count as a word tested
add 1 to wordCount
ELSE
@ pick RANDOM word from the working list
@ Put LinesFN(theTest) into wordsRemaining
@ Put RndFN(1,wordsRemaining) into wordLine
Put RndFN(1,wordCheck) into wordLine
put line wordLine of theTest into theWord
@ remove word from the working list
deleteLineVar theTest,wordLine
decrement wordCheck
@ count as a word tested
add 1 to wordCount
ENDIF