BlitzCoder Essentials
•
Home Page
•
About BlitzCoder
•
Contributors
•
Terms of Use
•
Email Us
Main Areas
•
BlitzCoder Chat
•
Discussions
•
Articles/Tutorials
•
Code Database
•
Link Database
•
Showcase Area
•
Worklogs
•
Competitions
Special Areas
•
Undocumented
Other Blitz Sites
•
Blitz Basic Home
•
Blitz Showcase
•
BlitzPlay Library
Forum Login
Username:
Password:
•
Register Now!
BlitzCoder Code Archives Page
Main Codes Page
"Select Case secrets"
, by thechange
The ability to use conditions in case statements.
Code
; It is known that Select Case structures are converted ; to an If structure internally at compile time. ; ; But you may want to use Select anyway to improve readability :o) ; There's another trick that's not well-known. ; ; When you specify True (or 1) as the Select parameter, ; you can use conditions as Case parameters: Select True Case Value < 0 Case Value = 0 Case Value > 0 And Value < 10 Case Value >= 10 And Value <= 100 Case Value >= 240 And Value <= 290 Case Value > 999 Default End Select ; Compared to using If: If Value < 0 Else If Value = 0 Else If Value > 0 And Value < 10 Else If Value >= 10 And Value <= 100 Else If Value >= 240 And Value <= 290 Else If Value > 999 Else End If ; Here's an example: For n = -1 To 11 Print n + " " + result ( n ) Next Function result$ ( n ) Select True Case n = 0 : Return "Zero" Case n >= 1 And n <= 5 : Return "One to Five" Case n >= 6 And n <= 9 : Return "Six to Nine" Case n = 10 : Return "Ten" Default : Return "Other" End Select End Function
Copyright(c) 2000-2004, BlitzCoder. All Rights Reserved.
Code software created by Krylar's Kreations