Author Topic: deleteLineVar bug?  (Read 1886 times)

carlk

  • Newbie
  • *
  • Posts: 13
deleteLineVar bug?
« on: January 19, 2011, 05:57:47 PM »
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.

Code: [Select]
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
« Last Edit: January 01, 1970, 12:00:00 AM by Guest »

Malkom

  • Administrator
  • Newbie
  • *****
  • Posts: 401
  • Here to help you
Re: deleteLineVar bug?
« Reply #1 on: January 20, 2011, 11:28:06 AM »
Thank you for this you have definitely found a bug :(

If the last item in the list is deleted then the carriage return associated with that item is not removed as it should be so leaving an empty line.
« Last Edit: January 01, 1970, 12:00:00 AM by Guest »
I am sorry but I do not have time to answer questions by PM or email.
If you post your questions in this forum then it might help others.

carlk

  • Newbie
  • *
  • Posts: 13
Re: deleteLineVar bug?
« Reply #2 on: January 20, 2011, 01:47:42 PM »
Actually, this occurred when the second to last item of my list was deleted, leaving the last item plus the CR/blank line.  That's why I noticed the problem - an empty "word" was presented whenever the last/empty line was randomly chosen instead of the actual last word.

[Added later]
The other puzzle here is that this bug only occurs when I am randomly plucking out lines from the variable.  It has never occurred when simply working in order from the top down through the list of words/lines.  Why should the functioning be different if some random line - any line other than the top/first one - is deleted?
« Last Edit: January 01, 1970, 12:00:00 AM by Guest »

Malkom

  • Administrator
  • Newbie
  • *****
  • Posts: 401
  • Here to help you
Re: deleteLineVar bug?
« Reply #3 on: January 21, 2011, 04:24:36 PM »
Its a strange bug this but thanks for the further info on the bug - my quick tests just showed up the failure on the last element.
« Last Edit: January 01, 1970, 12:00:00 AM by Guest »
I am sorry but I do not have time to answer questions by PM or email.
If you post your questions in this forum then it might help others.

 

anything