Help on Using a key to exit without using a loop

Please use this Board for QBasic related requests ( file research, programming, etc.)

Moderators:Administrator, Global Moderator

Post Reply
bobdole
Help on Using a key to exit without using a loop

Post by bobdole » Sun Jun 05, 2005 5:31 pm

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

Valerie
Sr. Member
Posts:54
Joined:Wed Dec 15, 2004 8:10 am
Location:Coromandel, NZ

Exit program

Post by Valerie » Wed Jun 08, 2005 4:07 am

Have you tried the ON KEY command??

See the QB Help for syntax etc...

Ralph
QBasic God
Posts:134
Joined:Sat Nov 06, 2004 2:27 am
Location:Katy, Texas

Post by Ralph » Thu Jun 16, 2005 2:46 am

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!
Ralph. Running QuickBASIC Version 4.5, Windows XP Home Edition, Version 2002, Service Pack 2, and HP LaserJet 4L printer.

Post Reply