vb net +检查Textbox1是否为< Texbox2

时间:2017-05-07 08:34:42

标签: vb.net

这是错的吗? 我有一个简单的表单,包含textbox1和textbox2以及一个按钮。 当我把Textbox1 = 259和textbox2 = 1500 我点击,他说"你的号码太高" 我尝试了151"你的号码太高" 我尝试了150" ok" 我尝试1500" ok" 我尝试1501"你的号码太高"

帮助.........

Public Class test

Private Sub test_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If TextBox1.Text > TextBox2.Text = True Then
        MsgBox("You're number is too high")
    Else
        MsgBox("ok")
    End If

End Sub

结束班

2 个答案:

答案 0 :(得分:0)

您必须使用Val命令。

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If Val(TextBox1.Text) > Val(TextBox2.Text) Then
  MsgBox("You're number is too high", "Wrong Input")
Else
  MsgBox("ok", "Input number") ' This also renames the msgbox itself, instead of just "error".
End If
End Sub

答案 1 :(得分:0)

If Val(TextBox1.Text) > Val(TextBox2.Text) Then
        MsgBox("You're number is too high")
    Else
        MsgBox("ok")
    End If

将字符串转换为整数,双精度,小数等时,需要使用Val(字符串)函数。