Yes, just like all previous code snippets..Nekrophidius wrote:You bonehead...that specific code is never gonna work. k$ is ALWAYS going to be w after the loop because the loop won't end until it is so your SELECT CASE will only ever work with CASE "w". Silly Swede...Z!re wrote:Code: Select all
DO k$ = INKEY$ LOOP UNTIL k$ = "w" SELECT CASE k$ [...]
help on limiting keys
I have left this dump.
(PaulUnknown's "nevermine" notwithstanding...)
Just remember, if you're going to use SELECT CASE after a keyboard input, you'd better have a CASE ELSE at the end of your case list, or you'll have to have a CASE for every key on the keyboard! Otherwise, after the first keystroke you're not checking for, the program bombs.
Just remember, if you're going to use SELECT CASE after a keyboard input, you'd better have a CASE ELSE at the end of your case list, or you'll have to have a CASE for every key on the keyboard! Otherwise, after the first keystroke you're not checking for, the program bombs.
--- Zim ---
--- Time flies like an arrow, but fruit flies like a banana ---
--- Time flies like an arrow, but fruit flies like a banana ---
Very sound advice, Zim. Hope it doesn't fall on deaf ears. What'd you say?Zim wrote:(PaulUnknown's "nevermine" notwithstanding...)
Just remember, if you're going to use SELECT CASE after a keyboard input, you'd better have a CASE ELSE at the end of your case list, or you'll have to have a CASE for every key on the keyboard! Otherwise, after the first keystroke you're not checking for, the program bombs.
-
- Coder
- Posts: 17
- Joined: Sat Aug 27, 2005 10:26 am
Sorry but I don't know what you are saying.Just remember, if you're going to use SELECT CASE after a keyboard input, you'd better have a CASE ELSE at the end of your case list, or you'll have to have a CASE for every key on the keyboard! Otherwise, after the first keystroke you're not checking for, the program bombs.
- {Nathan}
- Veteran
- Posts: 1169
- Joined: Thu Aug 19, 2004 6:08 pm
- Location: The wetlands of central Ohio, USA
- Contact:
If you use a Select Case, and you don't use a CASE ELSE,
then you will end up doing this.
You get what I mean, right? Typing out all of the letters? Yeah, thats right... but instead you can do this:
Yeah, you get it now? But if you command your CASEs to use subs/functions/GOTOs, then it will exit without doing anything which can REALLY screw your game/program/OS up...
*caugh* No, I didn't say just like in windows... *caugh*
I hope you got that...
then you will end up doing this.
Code: Select all
SELECT CASE Cheese$
CASE IS "A"
...
CASE IS "B"
...
CASE IS "C"
PRINT "TRY AGAIN"
CASE IS "D"
PRINT "TRY AGAIN"
CASE IS "E"
PRINT "TRY AGAIN"
CASE IS "F"
PRINT "TRY AGAIN"
...
CASE IS "Z"
PRINT "TRY AGAIN"
Code: Select all
SELECT CASE Cheese$
CASE IS "A"
PRINT "YOU WIN!"
CASE IS "B"
PRINT "YOU WIN!"
CASE ELSE
PRINT "YOU FAIL!"
*caugh* No, I didn't say just like in windows... *caugh*
I hope you got that...
-
- Coder
- Posts: 17
- Joined: Sat Aug 27, 2005 10:26 am
Right!
But you have to be absolutely sure that (at least) ONE of the cases is true, else the program will bomb. I usually do something like this:
Adding that one little line with a comment " 'do nothing " prevents the program from an abnormal abort. Very little code; good insurance; lots of bang for the buck.
But you have to be absolutely sure that (at least) ONE of the cases is true, else the program will bomb. I usually do something like this:
Code: Select all
Input "Option (1) or (2) ", k
Select Case k
case 1 : print "You said ONE"
case 2 : print "You said TWO"
case else 'do nothing
End Select
--- Zim ---
--- Time flies like an arrow, but fruit flies like a banana ---
--- Time flies like an arrow, but fruit flies like a banana ---
Good point, Zim. But if the user hits anything other than 1 or 2, he would get absolutely no output response and wonder ???.Zim wrote:Right!
But you have to be absolutely sure that (at least) ONE of the cases is true, else the program will bomb. I usually do something like this:
Adding that one little line with a comment " 'do nothing " prevents the program from an abnormal abort. Very little code; good insurance; lots of bang for the buck.Code: Select all
Input "Option (1) or (2) ", k Select Case k case 1 : print "You said ONE" case 2 : print "You said TWO" case else 'do nothing End Select
I would enhance your code as follows:
Code: Select all
Input "Option (1) or (2) ", k
Select Case k
case 1 : print "You said ONE"
case 2 : print "You said TWO"
case else : print "Error: Invalid Option"
End Select