Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Problem with Select Case in VB.net 2003

sbdutoitsbdutoit Posts: 1Member
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 Posts: 532Member
    : 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.