Posts: 938
Threads: 104
Joined: Dec 2002
hey everybody... I am kinda confuzzled with the CASE commands 'n stuff. Everybody tells me that using CASE is a lot better than using a bunch of IF-THENS but I really don't know how to use the CASE command. could someone give me an example of CASE? I think that if I got this CASE down then my program could slim down quite a lot.... (I use IF-THEN statements TOO MUCH)
Thanks
ovaProgramming.
One night I had a dream where I was breaking balls. The next morning,
BALLSBREAKER was born.
Quote: Excellent. Now you can have things without paying for them.
BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it
.
-----------------------------
Posts: 31
Threads: 7
Joined: Nov 2002
Code:
'Hopefully this will work, I'm kinda pulling it out of nowhere
DO
a$=INPUT$(1)
a$=RIGHT$(a$,1)
a$=UCASE$(a$)
a%=ASC(a$)
SELECT CASE a%
case 27 'esc pressed
PRINT "You Pressed the Esc Key"
END
CASE 32 'spacebar pressed
PRINT "You Pressed the spacebar"
case 72 'Up pushed
Print "You pushed up/H"
END SELECT
a$=INPUT$(1)
CLS
LOOP
So, here is how it should work:
choose a variable you want to compare (in the above example, a%) and precede it with a SELECT CASE statement
Then, write CASE
anything to have it execute the statements inbetween that CASE and the next CASE when
anything is true.
As a note, it does not have to just be a number, you could also say
Code:
CASE IS > 10
'or
CASE IS (>64 and <91) 'checks if a letter key has been pushed
Hope that helps, if you want more, just ask and I will try to explain it.[/code]
Posts: 480
Threads: 24
Joined: Mar 2003
Code:
INPUT "Enter a number", N
SELECT CASE N
CASE 0:
PRINT "You entered 0!"
CASE 1,2,3,4,5:
PRINT "You entered 1,2,3,4, or 5!"
CASE 6 TO 10:
PRINT "You entered 6,7,8,9, or 10!"
CASE IS > 10
PRINT "You entered a number higher than 10!"
CASE IS < 0
PRINT "You entered a negative number!"
CASE ELSE
PRINT "You entered a non-integer!"
END SELECT
Get it?
*peace*
Meg.
Posts: 1,407
Threads: 117
Joined: Dec 2002
You use SELECT when you have a single check and different cases. The advantage is the condition is checked only once and not once per case as it would happen with different IFs
Antoni
Posts: 938
Threads: 104
Joined: Dec 2002
OKay, thanks, that clears up pretty much the whole thing for me. Thanks again!
ovaProgramming.
One night I had a dream where I was breaking balls. The next morning,
BALLSBREAKER was born.
Quote: Excellent. Now you can have things without paying for them.
BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it
.
-----------------------------