0

所以我正在尝试编写一个按钮来读取用户输入的年龄并确定他们收到的价格。以下是我尝试这样做但没有运气的方法。

 Private Sub btnSelect_Click(sender As Object, e As EventArgs) Handles btnSelect.Click
    Dim txtage As String
    txtage = lblPrice.Text.ToUpper
    Select Case txtage
        Case CStr(0) To CStr(3)
            lblPrice.Text = "0"
        Case CStr(4) To CStr(63)
            lblPrice.Text = "9"

    End Select

End Sub

我有 Option Explicit On, Option Strict On, Option Infer Off,

我在这里错过了什么或做错了什么?谢谢,麻烦您了。

4

1 回答 1

3

然后从正确的位置获取值,并使用一些代码保护,Integer.TryParse因为您从字符串中读取。

Private Sub btnSelect_Click(sender As Object, e As EventArgs) Handles btnSelect.Click
  Dim age As Integer
  If Integer.TryParse(txtage.Text, age) Then
    Select Case age
      Case 0 To 3
        lblPrice.Text = "0"
      Case 4 To 63
        lblPrice.Text = "9"
    End Select
  End If
End Sub
于 2014-11-18T03:30:03.230 回答