|
-
Sep 21st, 2000, 02:46 PM
#1
Thread Starter
Hyperactive Member
Can someone explain the command "case" better to me? Is it better then if,else,then? Show a example. I have a class called introduction to programming design and im trying to jump ahead but the book doesnt explain it clear enough. Can you help?
-RaY
VB .Net 2010 (Ultimate)
-
Sep 21st, 2000, 02:56 PM
#2
It's used in the Select Case statement. Select Case is used to choose between different results.
Code:
Retval = InputBox("Enter your age")
Select Case Retval
Case 20
MsgBox "You are the same age as me"
Case 80
MsgBox "You are older than my grandparents"
Case Is < 12
MsgBox "You are still a kid"
Case Else
MsgBox "Your age does not fit this criteria"
End Select
-
Sep 21st, 2000, 02:57 PM
#3
Select Case is similar to the 'if..then..else' construct, but I like Case better for 2 reasons.
It is more readable (especially if there are many possibilities).
code:
Select Case (month)
Case "January"
'do something
Case "February"
'do something else
'etc...
End Select
is more readable than
If (month = "January") then
'do something
Else
If (month = "February") then
'etc...
end if
Also I understand that Select Case is better performance wise. something about the number of comparisons?
I'm new to VB myself so correct me if I'm wrong.
-
Sep 21st, 2000, 02:58 PM
#4
Thread Starter
Hyperactive Member
Ohhh
So its just like the enlgish term "In case"
-RaY
VB .Net 2010 (Ultimate)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|