Results 1 to 12 of 12

Thread: What is wrong with SELECT CASE?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    296

    What is wrong with SELECT CASE?

    Is Select Case code work this way? Although the number is available within the Select Case, it reads only CASE ELSE and prompt me a messagbox according below. What is wrong?

    VB Code:
    1. Private Sub txtantdriver_Validate(Cancel As Boolean)
    2. Dim Number As Integer
    3.  
    4. Select Case Number
    5.  
    6.     Case "1"
    7.     txtantdriver.Text = "The Insured."
    8.    
    9.     Case "2"
    10.     txtantdriver.Text = "Any other person who is driving on the Insured's order or with his permission."
    11.  
    12.     Case "3"
    13.     txtantdriver.Text = "Ant person who is driving on the Insured order or with permission."
    14.    
    15.     Case "4"
    16.     txtantdriver.Text = "Any other person provided he is in the PolicyHolder employ is driving on his order or with his permission."
    17.  
    18.     Case "5"
    19.     txtantdriver.Text = "Any person provided he is in the PolicyHolder employ and is driving on thier order or with their permission."
    20.    
    21.     Case Else
    22.     MsgBox "Case Number not found. Please Try again", vbExclamation, "Case Number"
    23.  
    24. End Select

  2. #2
    Fanatic Member
    Join Date
    Feb 2002
    Location
    SE England
    Posts
    732
    You are comparing an integer to a string...

    Remove the quotes from around the numbers...

    Case "1"

    Should be

    Case 1
    Leather Face is comin...


    MCSD

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    296
    Leather, i did that but i still face the same problem.

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Well since you dim the number and then ask it's value wouldn't it be zero and thus be else?

    VB Code:
    1. Dim Number As Integer
    2.  
    3. Select Case Number
    4. Case 0
    5.   msgbox Number
    6. End Select

  5. #5
    Fanatic Member
    Join Date
    Feb 2002
    Location
    SE England
    Posts
    732

    Wink

    Well spotted Edneeis... I should have clocked that one, a bit early in the morning though.

    Cutepretty... You have just created the variable "Number" so it will always be zero when the select block runs...


    Add this debug line..

    Dim Number As Integer

    Debug.Print "Number Currently: " & Number

    Select Case Number
    Leather Face is comin...


    MCSD

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    296
    yeah, it is always Zero. So how do i get this work?

  7. #7
    Fanatic Member
    Join Date
    Feb 2002
    Location
    SE England
    Posts
    732
    Eh?

    Well you need to retrieve the number from somewhere...

    What does the number relate to?
    Leather Face is comin...


    MCSD

  8. #8
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    i.e.

    VB Code:
    1. Private Sub cbxAntDriver_Validate(Cancel As Boolean)
    2.  
    3. Select Case cbxAntDriver
    4.     Case 1:
    5.         txtantdriver.Text = "The Insured."
    6.     Case 2:
    7.         txtantdriver.Text = "Any other person who is driving on the Insured's order or with his permission."
    8.     Case 3:
    9.         txtantdriver.Text = "Ant person who is driving on the Insured order or with permission."
    10.     Case 4:
    11.         txtantdriver.Text = "Any other person provided he is in the PolicyHolder employ is driving on his order or with his permission."
    12.     Case 5:
    13.         txtantdriver.Text = "Any person provided he is in the PolicyHolder employ and is driving on thier order or with their permission."
    14.     Case Else
    15.         MsgBox "Case Number not found. Please Try again", vbExclamation, "Case Number"
    16. End Select
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    296
    Leather,
    User has to enter the number in a textbox named txtantdriver.

  10. #10
    Fanatic Member
    Join Date
    Feb 2002
    Location
    SE England
    Posts
    732
    Ok so you need to retrieve the contents of teh text box...


    Dim Number as integer

    ' Check that the user has made a valid entry.
    If isNumeric(txtantdriver.Text) = False Then
    msgbox "You must enter a number.",vbokonly,"Invalid Input"
    txtantdriver.SetFocus
    Exit Sub
    End if

    ' Convert the text into an integer.
    Number = cInt(txtantdriver.Text)


    Select Case Number
    etc....
    Leather Face is comin...


    MCSD

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    296
    thanks Leather. darre1, gave me the solution. Try his solution. anyway, tx everyone

  12. #12
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    welcome
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

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