Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Continue by hitting a certain key
#11
I dont get it, lol.
S VERDAD?!
Reply
#12
Me neither.

*considers imprisoning Valerie for this comment*
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#13
C'mon people.

GOTO = instruction
HELL = destination

Programmers think GOTO is worse than HELL.
Reply
#14
Quote:You should use a library. Unless you enjoy POUNDING on your keyboard.

:lol:

And sorry to kill this thread with the all-encompassing answer, but:

Code:
numofkeystocheck% = 4   ' Set to the number of keys in the array you wish to check for
DIM keys(1 TO numofkeystocheck%) AS STRING * 1

' Insert the scancodes you wanna check for here
keys(1) = CHR$(27)
keys(2) = CHR$(13)
keys(3) = CHR$(32)
keys(4) = CHR$(65)

' The loop
DO
  K$ = ""
  DO
    K$ = INKEY$
  LOOP UNTIL K$ <> ""
  FOR I = 1 TO numofkeystocheck%
    IF K$ = keys(I) THEN EXIT DO
  NEXT I
LOOP

PRINT "You pressed a key in the array, index number"; I

Tongue
Reply
#15
He used EXIT DO, see? Wink
Reply
#16
Exit do works fine, but I've been programming for ages now, and I have never encounted problems with GOTO. What is wrong with it?
eminiscing about trapezoids in conjunction with stratospherical parabolas:

No questions asked.

www.stickskate.com
Reply
#17
A modification of Oracle's code
Code:
'Choices are Esc, Enter, Space, and A
Choice$ = CHR$(27) + CHR$(13) + CHR$(32) + CHR$(65)

' The loop
DO
  DO
    K$ = INKEY$
  LOOP UNTIL K$ <> ""
LOOP WHILE INSTR(Choice$, K$) = 0

SELECT CASE K$
  CASE CHR$($27)
    K$ = "Esc"
  CASE CHR$($13)
    K$ = "Enter"
  CASE CHR$($32)
    K$ = "Space"
  CASE ELSE  
END SELECT

PRINT "You pressed an available key: "; K$
The loop is more concise. The code after the loop is longer, but it is like what you will often use in a program.
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)

For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Reply
#18
In previous projects they have hammered me for using the goto command. And, in some sense for people it is bad because they don't ever compact their modules. When you get to humungus programs, that GOTO space gets removed or you can't expand anymore. But, I found it really usefull when trying to create certain text games where you must return to a specific place, and in fact I still use it. Its alot easier to comprehend than all those loops and dim thingys. :bounce: :bounce: :bounce: :bounce: :bounce: :bounce: :bounce: :bounce: :bounce: :bounce: :bounce: :bounce: :bounce: :lol:
S VERDAD?!
Reply
#19
Andy,
The careful use of GOTO's is okay, but they make the code much harder to follow than using loops and subs. As a result it is much harder to debug.

Terry,
You find loops and arrays ("those dim thingys') hard to understand because you haven't learned to use them. Once you do you will find that they make programming much easier. among other things, they save you having to write the same code over and over again.
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)

For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Reply
#20
Ah, but my code loops around again if the user doesn't press an available key Tongue Wink
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)