Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Problem with Select Case in VB.net 2003

sbdutoitsbdutoit Member Posts: 1
Public Sub GetTable()
Select Case cboMotorTable.Text
Case "Private Cars"
Select Case txtValue.Text
Case 0 To 100000
strRateTable = "Private_15000"
Case 100001 To 200000
strRateTable = "Private_100000"
Case 200001 To 300000
strRateTable = "Private_200000"
Case Is > 300000
strRateTable = "Private_300000"
End Select

.........
.........
.........

End Select
End Sub

In the above snippet if the value in txt.Value.Text is either 0 or 100000 then strRateTable = Private_15000. If it is any other number between 1 and 99999 then strRateTable is Private_100000. The rest of the case statements work fine it is only the first one that does not behave correctly. I have also tried changing the first one to
Case is <100000 which also does not work.

Can anyone help me with this problem. By the way the code works fine in VBA under Access 2003.

Comments

  • dokken2dokken2 Member Posts: 532
    : Public Sub GetTable()
    : Select Case cboMotorTable.Text
    : Case "Private Cars"
    : Select Case txtValue.Text
    : Case 0 To 100000
    : strRateTable = "Private_15000"
    : Case 100001 To 200000
    : strRateTable = "Private_100000"
    : Case 200001 To 300000
    : strRateTable = "Private_200000"
    : Case Is > 300000
    : strRateTable = "Private_300000"
    : End Select
    :
    : .........
    : .........
    : .........
    :
    : End Select
    : End Sub
    :
    : In the above snippet if the value in txt.Value.Text is either 0 or 100000 then strRateTable = Private_15000. If it is any other number between 1 and 99999 then strRateTable is Private_100000. The rest of the case statements work fine it is only the first one that does not behave correctly. I have also tried changing the first one to
    : Case is <100000 which also does not work.
    :
    : Can anyone help me with this problem. By the way the code works fine in VBA under Access 2003.
    :

    The code seems to work for me, I would suggest explicitly converting the textbox value to an integer.

    [code]
    Select Case cboMotorTable.Text
    Case "Private Cars"
    Select Case CInt(txtValue.Text) 'convert textbox to integer
    Case 0 To 100000
    strRateTable = "Private_15000"
    Case 100001 To 200000
    strRateTable = "Private_100000"
    Case 200001 To 300000
    strRateTable = "Private_200000"
    Case Is > 300000
    strRateTable = "Private_300000"
    Case Else
    MsgBox("else?")
    End Select
    Case Else
    MsgBox("else?")
    End Select
    [/code]

    if you want strRateTable = Private_15000 *only* when the textbox is 0 *or* 10000 then rewrite the select statement-

    [code]
    Case 0
    strRateTable = "Private_15000"
    Case 100000
    strRateTable = "Private_15000"
    [/code]

Sign In or Register to comment.