Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Continue by hitting a certain key
#1
A simple question:
The SLEEP command stops the application until the user pushes any key, but how do I do to force the user to hit a certain key (eg space) to let him continue running the program?

Thanks in advance!
size=8]Select From Neoneh Where QBKnowledge = 1337
IF RS.EOF THEN Response.Write "He's a noob.."
ELSE
Response.Write "No, that's impossible!"
END IF[/size]
Reply
#2
SLEEP 6000


Hehehe!

I don't know...


WHILE Inkey$=""
WEND

:normal:
Reply
#3
Code:
DO: LOOP UNTIL INKEY$=" "
/post]
Reply
#4
Quote:
Code:
DO: LOOP UNTIL INKEY$=" "

Kanoners! tack Tongue
size=8]Select From Neoneh Where QBKnowledge = 1337
IF RS.EOF THEN Response.Write "He's a noob.."
ELSE
Response.Write "No, that's impossible!"
END IF[/size]
Reply
#5
Code:
Do
khb$ = inkey$
'your code goes here
loop untill khb$ = "g"

You can replace g with any other letter, number or character.

Or if you want to use a key like escape then you use the ascii code chr$(27). where 27 is the code for ESC.
You can view a list of all the ascii character codes, using the qbasic help. In the contents, there is a link to them.

Code:
Do
KHB$ = inkey$
'your code here
loop until inkey$ = chr$(27)

Also you could use

Code:
DO
khb$ = inkey$
'your code here
if inkey$ = "g" or inkey$ = chr$(27) then goto 100
loop
100
'more code

note: the "or inkey$ = chr$(27)", is not necessary.
eminiscing about trapezoids in conjunction with stratospherical parabolas:

No questions asked.

www.stickskate.com
Reply
#6
try to avoid GOTO. Better use EXIT DO in this example (the last one).
Reply
#7
You should use a library. Unless you enjoy POUNDING on your keyboard.
Reply
#8
In this case I personally (although my opinion is really inferior compared to some other people here) would use something like;

99
INPUT " "; yourvariablehere
IF yourvariablehere$ = "key you want them to hit here" THEN
GOTO 1 '(Place a one in front of you continued program)
END IF
BEEP
PRINT "Invalid Answer"
SLEEP 5
GOTO 99

And that would tell the person that their answer was incorrect. By using this system you can also make other keys register certain commands; such as to just exit the program altogether, or stop it for modifications. Its all up to you. However, when using the goto and input commands together, it is importaint not to get caught in an infinate loop.
So, yeah. There are some cases when the GOTO command is not evil. You just have to know how to harness its evil power. Smile.
S VERDAD?!
Reply
#9
When told to "Goto Hell" a programmer believes the instruction is worse than the destination
Reply
#10
Quote:When told to "Goto Hell" a programmer believes the instruction is worse than the destination
Good joke, I'm assuming you're new to this forum, but not to programming? Tongue
am an asshole. Get used to it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)