vb.netselect-case

Select Case between number


I try a select case between number. Each 150000 the code the Textbox5 change on click button.

Select Case TextBox5.Text
    Case 0 To 150000
        TextBox6.Text = "-"
    Case 150001 To 300001
        TextBox6.Text = "+1-"
    Case 300002 To 450002
        TextBox6.Text = "+2-"
    Case 450003 To 600003
        TextBox6.Text = "+3-"
    Case 600004 To 750004
        TextBox6.Text = "+4-"
    Case 750005 To 900005
        TextBox6.Text = "+5-"
    Case 900006 To 1050006
        TextBox6.Text = "+6-"
    Case Else
        TextBox6.Text = "+Extra-"
End Select

When I try any number between 900006 to 1050006 I have "+Extra-" not "+6-" and try over 1050006 I have "-"


Solution

  • Dim i as Long
    If Long.TryParse(TextBox5.Text, i)
      Select Case i
        Case 0 To 150000
          TextBox6.Text = "-"
        Case 150001 To 300001
          TextBox6.Text = "+1-"
       Case 300002 To 450002
          TextBox6.Text = "+2-"
        Case 450003 To 600003
          TextBox6.Text = "+3-"
        Case 600004 To 750004
          TextBox6.Text = "+4-"
        Case 750005 To 900005
          TextBox6.Text = "+5-"
        Case 900006 To 1050006
          TextBox6.Text = "+6-"
        Case Else
          TextBox6.Text = "+Extra-"
      End Select
    Else
      TextBox6.Text = "Not a Number"
    End If
    

    Modify to your requirements.