Results 1 to 4 of 4

Thread: Case?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344
    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)

  2. #2
    Guest
    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

  3. #3
    Guest
    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.



  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344

    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
  •  



Click Here to Expand Forum to Full Width