program help (if you have a free sec)
-
- Coder
- Posts: 18
- Joined: Fri Feb 11, 2005 11:51 am
- Location: Lea Monde Ruins
program help (if you have a free sec)
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?)
RANDOMIZE TIMER
'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$
PRINT
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,
Agent_Firestalker
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?)
RANDOMIZE TIMER
'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,
Agent_Firestalker
"I ask you, is this a job for intelligent men?"
"Well show me one, i'll ask him?"
Val and Earl - "Tremors"
"Well show me one, i'll ask him?"
Val and Earl - "Tremors"
close/re-open file
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
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
-
- Coder
- Posts: 18
- Joined: Fri Feb 11, 2005 11:51 am
- Location: Lea Monde Ruins
Glad to help. (Heh... 'SEEK and ye shall find' ).
Visit Dav's Qbasic Site at: www.qbasicnews.com/dav
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
I dunno
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:
DO WHILE NOT(EOF(1))
You could also use: IF NOT(EOF(1)) THEN INPUT #1, verse$
Ted
It is important that you not pass the End Of File. I usually use:
DO WHILE NOT(EOF(1))
You could also use: IF NOT(EOF(1)) THEN INPUT #1, verse$
Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
- Seb McClouth
- Veteran
- Posts: 342
- Joined: Wed Nov 09, 2005 7:47 am
- Location: Inside the Matrix...
- Contact:
Erm it could be me but wouldn't
grtz
resolve into a problem since in the txt-file, it's written likeFOR count = 1 TO num
INPUT #1, verse$
INPUT #1, reference$
NEXT count
Wouldn't it have to be sumfin likeeveryone has sinned, rom 2:20
Code: Select all
FOR count = 1 TO num
INPUT #1, verse$, reference$
NEXT count
QBinux is a Linux distribution with the aim of integrating the work of the vast community of free software developers at Pete's QBASIC Site in order to create a modern, performant, safe and easy to use system for system administrators and desktop users.
-
- Coder
- Posts: 18
- Joined: Fri Feb 11, 2005 11:51 am
- Location: Lea Monde Ruins
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...
Agent_Firestalker
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...
Agent_Firestalker
"I ask you, is this a job for intelligent men?"
"Well show me one, i'll ask him?"
Val and Earl - "Tremors"
"Well show me one, i'll ask him?"
Val and Earl - "Tremors"
- Seb McClouth
- Veteran
- Posts: 342
- Joined: Wed Nov 09, 2005 7:47 am
- Location: Inside the Matrix...
- Contact:
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.
grtz
In Linux this'd be easy
Code: Select all
shutdown -h now
grtz
QBinux is a Linux distribution with the aim of integrating the work of the vast community of free software developers at Pete's QBASIC Site in order to create a modern, performant, safe and easy to use system for system administrators and desktop users.