You're welcome.
Quote: "I'm not exactly sure how to use those Case,Endcase,Select,etc. Are here any tutorials'guides that discuss that topid that you may know of?"
Normally, I would point you to TDK's tutorials (look in the tutorial thread that is a sticky on this board), but I couldn't find any that addressed SELECT / ENDSELECT, so I will do my best to help you with it.
SELECT / ENDSELECT is normally used when you have a lot of comparisons to make and it makes your code a lot more readable and easier to understand. Within the SELECT / ENDSELECT code, you use the CASE / ENDCASE commands for the actual value comparisons. It is always wise to place a DEFAULT CASE in your code, because users don't always enter what they are supposed to (or values are different than you figured them to be) and it serves kindof like an error trap.
For example, if you want to code a program that asks a user to input a particular month, you would have to look at up to 13 different things; (the 12 months, plus the default case). This would be tedious with IF / THEN statements.
You can also use more than one value in the case statement. Like this:
repeat
cls
center text screen width() / 2,screen height() - 40,"Enter 'quit' to exit."
set cursor 100,10
input "Please enter your name: ";name$
name$ = lower$(name$)
select name$
case "chris","lbfn"
text 100,100,"Picked either Chris or LBFN"
endcase
case "mike","anderson"
text 100,100,"Picked either Mike or Anderson"
endcase
case "jared","willoughby"
text 100,100,"picked Jared or Willoughby"
endcase
case "quit"
exit
endcase
case default
text 100,100,"default"
endcase
endselect
if name$ <> "quit" then wait key
until name$ = "quit"
end
In the months' example, you can use multiple case variables like this:
repeat
cls
center text screen width() / 2,screen height() - 40,"Enter 'quit' to exit."
set cursor 100,10
input "Please pick a month with 30 days in it: ";name$
name$ = lower$(name$)
select name$
case "april","june","september","november"
text 100,100,"Yes, that is correct. You get a gold star."
endcase
case "january","march","may","july","august","october","december"
text 100,100,"No, that month has 31 days."
text 100,120,"Please try again."
endcase
case "february"
text 100,100,"February had 28 days this year."
text 100,120,"Please try again."
endcase
case "quit"
exit
endcase
case default
text 100,100,"Error: Please check your spelling."
endcase
endselect
if name$ <> "quit" then wait key
until name$ = "quit"
end
You can use Case / ENDCASE to branch to different parts of your program, like this:
level = 3
cls
select level
case 1
gosub LevelOne
endcase
case 2
gosub LevelTwo
endcase
case 3
gosub LevelThree
endcase
case default
if level > 3 then level = 3 : gosub LevelThree
if level <> 1 and level <> 2 and level <> 3 then level = 1 : gosub LevelOne
endcase
endselect
wait key
end
LevelOne:
text 100,100,"At LevelOne code...."
` code
` code
` more code
return
LevelTwo:
text 100,100,"At LevelTwo code...."
` code
` code
` more code
return
LevelThree:
text 100,100,"At LevelThree code...."
` code
` code
` more code
` gimme teh codez :-D
return
Change the value of 'level' to see what happens.
I hope this is helpful. If you have any more questions, please let me know and I will try to help.
Good luck,
LB