Page 1 of 1

Help on Using a key to exit without using a loop

Posted: Sun Jun 05, 2005 5:31 pm
by bobdole
ok i need to use a key command to end this program and i already have a loop so i dont know if i could put one anywhere else, keep it easy too im just beginning/
i also have if input=-1 then end (for debugging) its temporary
and i added all the menus and crap into comments just for a lil' bit to go straight to the middle.. here it is
<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<================>>>>>>>>>>>>>>>>>>

Code: Select all

'CLS
'beginning1:
'COLOR 14
'LOCATE 12, 28
'PRINT "Main Menu"
'COLOR 4
'LOCATE 14, 26
'PRINT "1) Learn More About Exponents"
'COLOR 2
'LOCATE 16, 26
'PRINT "2) Shape Stuff"
'LOCATE 18, 26
'COLOR 14
'PRINT "3) Exit"
'COLOR 12
'LOCATE 20, 26
'INPUT "Choice?"; chc
'SELECT CASE chc


'CASE 1

DO
CLS


RANDOMIZE TIMER
L% = INT(RND * 8) + 1
R% = INT(RND * 9) + 1
T! = INT(R% ^ L%)

COLOR 14
LOCATE 1, 28
PRINT "Answer the Question";
COLOR 4
LOCATE 2, 28
PRINT "If You Get It Wrong It Will tell you the number,and re-randomize it"

LOCATE 5, 6
COLOR 4
PRINT ""; R%
COLOR 13
LOCATE 7, 6
PRINT "to the power of"; L%
IF G% = -1 THEN END
COLOR 2
LOCATE , 28
INPUT "Your Answer: ", G%
answer: PRINT "WRONG! The answer was:"; T!
SLEEP 1
COLOR 1
LOCATE , 30
LOOP UNTIL G% = T!


CLS
COLOR 2
LOCATE 12, 28
PRINT "Good Job"
PRINT ""
SLEEP 1
CLS
END


'CASE 2
SCREEN 12
CLS
LOCATE 12, 28
COLOR 13
PRINT "Here are some Questions"
PSET (170, 145), 4

DRAW "r220"
DRAW "ta15 h180 ta 0 d126 "

END

'CASE 3
COLOR 1
LOCATE 24, 40
PRINT "Okay, Cya."
END

'CASE ELSE
LOCATE 26, 45
COLOR 10
PRINT "Aw, Come on just put in the numbers, it's not rocket science"
'GOTO beginning1

'END SELECT

END

Exit program

Posted: Wed Jun 08, 2005 4:07 am
by Valerie
Have you tried the ON KEY command??

See the QB Help for syntax etc...

Posted: Thu Jun 16, 2005 2:46 am
by Ralph
BobDole:
Just something I use, frequently, when I'm just testing, instead of remarking out so much!

For your case, just enter a new, first line:
GOTO TEST:
Then, just before your first DO, enter:
TEST:

When you have done all your debugging, and the program runs fine, you can either remark out or delete the first line. You can leave the label, TEST:, in your code, as it does nothing, or, if you wish to clean it up, delete it. In any case, this involves only two, short lines of code, and it sure saves time!