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
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]
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
OKay, thanks, that clears up pretty much the whole thing for me. Thanks again!