Page 1 of 1

program help (if you have a free sec)

Posted: Thu Jul 17, 2008 1:06 pm
by Agent_Firestalker
I'm trying to make a program that will help me memorize bible verses, but it's got a problem. (could be my lousdy programming. If anyone reading has a sec, read on...

It randomly picks a verse from the file verses.txt (see bottom of post for txt sample) and then asks you for the reference. It lowercases the refernce and compares it to the reference (ref's follow verses in txt file)
You must get three right to close the program.

(On a side note, if I put this in my startup folder and have three wrong guess cause a logoff, can QB run XP's logoff and shutdown commands?)


'open file
OPEN "c:\qbasic\verses.txt" FOR INPUT AS #1

'clear variable "count"
count1 = 0
count2 = 0

start: CLS
'randomly determine which line of file to read
num = INT(RND * 3) + 1

'skips through file to specified line
FOR count = 1 TO num
INPUT #1, verse$
INPUT #1, reference$
NEXT count

'the verse display and user prompt
PRINT verse$
INPUT " Reference?: "; guess$

'if verse # selected (count) is same as last one/two used, get another number
'(start over)
IF count = used1 OR count = used2 THEN GOTO start

'stores used verses so no verse is used twice
IF count1 = 0 THEN count = used1
IF count1 <> 0 AND count2 = 0 THEN count = used2

'checking guess with reference
guess$ = LCASE$(guess$)

IF guess$ = reference$ THEN PRINT : PRINT "Correct!": SLEEP 2: correctnum = correctnum+1
IF guess$ <> reference$ THEN PRINT : PRINT "wrong": GOTO start
IF correctnum = 3 THEN PRINT "Nice job!"
IF correctnum < 3 THEN GOTO start

verses.txt (sample, verses aren't real)
everyone has sinned, rom 2:20
Jesus loves you, matt 12:1
pray often, john 14:1
in the beginning, gen 1:1

If anything is unclear, post your questions.
Thanks for your time,

close/re-open file

Posted: Thu Jul 17, 2008 5:25 pm
by Dav
The error INPUT PAST END OF FILE occurs because the file pointer has already read through the verses.txt file, and you're letting INPUT keep reading the file without pointing it back to the beginning of the verses.txt file.

There are several ways to fix the code. Probably the easiest way without re-writing a bunch is to just add " SEEK #1, 1 " after the FOR/NEXT that steps through all the lines. That will put the file pointer to the beginning of the OPENed file, so when INPUT is called again it will be back at the beginning of the verses.txt file.

- Dav

Posted: Thu Jul 17, 2008 5:27 pm
by Agent_Firestalker
Commands you never remember... SEEK.

Thanks, Dav

Posted: Thu Jul 17, 2008 5:31 pm
by Dav
Glad to help. (Heh... 'SEEK and ye shall find' :wink: ).

Posted: Fri Jul 18, 2008 10:14 am
by Ralph
Yes, Dav, but Agent_Firestalker used the other one, Ask and thou shalt receive. And, it worked for the Agent! Ha, ha, couldn't pass that one up. :)

I dunno

Posted: Fri Jul 18, 2008 12:10 pm
by burger2227
I think it is best to just close the file when you are done with it. Then reopen it when you need to read it again. You could make a SUB program with the OPEN and CLOSE and your loop.

It is important that you not pass the End Of File. I usually use:


You could also use: IF NOT(EOF(1)) THEN INPUT #1, verse$


Posted: Sat Jul 19, 2008 9:03 am
by Seb McClouth
Erm it could be me but wouldn't
FOR count = 1 TO num
INPUT #1, verse$
INPUT #1, reference$
NEXT count
resolve into a problem since in the txt-file, it's written like
everyone has sinned, rom 2:20
Wouldn't it have to be sumfin like

Code: Select all

FOR count = 1 TO num 
INPUT #1, verse$, reference$ 
NEXT count

Posted: Sun Jul 20, 2008 10:24 pm
by Agent_Firestalker
I thought i tried that, seb.. but I guess i've been working on XHTML too long lately.

Thanks all for your posts. It works now.
I just have to test it now by putting it in startup. (I could make it user specific, but since i'm the only user on my machine, startup works.)

Rock on...

Posted: Mon Jul 21, 2008 2:08 am
by Seb McClouth
I'm sure there's a way to log off even shutdown the machine if you got the answers wrong. Just look around with google.

In Linux this'd be easy

Code: Select all

shutdown -h now