Last year, when I first joined the LB/JB club, while writing a simple game using three graphicBox elements, I had a need to evaluate the contents of all three boxes, THEN...do something... for each of the 120 possibilities. This could easily done with multiple IF (a=?) AND (b=?) AND ©=?) THEN... do something. After considering several methods, I decided to use the SELECT CASE command, something I had never used before.
At first, I tried SELECT CASE a, b, c, but this always returned a syntax error. I got around this by making a string of the values for all graphicBoxes, curVal$=a;b;c. This produced 120 unique strings for use with the case statement, using:
SELECT CASE curVal$
CASE "543" 'quotes used to identify the string
'do something
CASE "542" : do something 'Single line for short actions
CASE "541" : do something 'Single line for short actions
'.... and on for all possibilities...
END SELECT
...which was certainly easier to type and easier to read than entering 120 IF...THEN statements...
IF (a=5) AND (b=4) AND (c=3) THEN
'do something
END IF
IF ....(119 other statements) THEN
'do something
END IF
The first method worked, but I continued to experiment and hit upon the correct syntax I had been unable to find in the help files. When using SELECT CASE for multiple variables, the proper form is:
SELECT CASE a; b; c 'NOTE the use of semi-colons
CASE 5;4;3
'do something
'can be several lines for each case
CASE 5;4;2 : do something 'single line format for short actions.
CASE 5;4;1 : do something 'single line format for short actions.
'...and so on....
END SELECT
I knew the help files say you can evaluate multiple expressions, but I was unable to find the exact form, so I worked around the problem using curVal$, but I'm sure SELECT CASE a; b; c is the more correct. The single line format was also easiest to enter for 120 actions.
By the way... if you want to try the game I wrote using 120 SELECT CASE statements, a few images and one WAV file, download from http://jbusers.com/phpBB/viewtopic.php?t=30 Most of my chums say they were only thrown to the lions a few times before they learned how to beat "Smarticus." Good luck!
For more on SELECT CASE, see Janet Terra's tutorial at http://justbasic.conforums.com/index.cgi?board=tutorial&action=display&num=1109020923
Don't you think these newsletters and forum boards are so much better than sliced bread? No calories and no carbohydrates! Just tips and information you can use to develop your skills as a basic programmer!