2017-05-07 3 views
-1

これは間違っていますか? 私は、テキストボックス1とテキストボックス2とボタンを持つ単純なフォームを持っています。 Textbox1 = 259とtextbox2 = 1500を入力すると、 私はクリックすると「あなたは数字が高すぎます」と言います 私は151を試しています "数字が高すぎます" 私は150 "ok"を試します 私は1500 "OK" は、私が1501年には、あなたがValコマンドを使用する必要がvb net + Textbox1が<Texbox2であることを確認する

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 

エンドクラス

+1

など、文字列を整数に変換する際、ダブル、小数点以下をヴァル(文字列)関数を使用する必要があります。前者の場合は文字列を数値に変換して比較します。また、Ifの= Trueを削除します。 – dbasnett

+0

文字列を比較しています。 "259"は実際には "1500"より大きく、 "2"は "1"の後でソートされます。 Val()とCDec()は変換を行うのに便利です。 Decimal.TryParse()は、ユーザーが実際に数字を入力したかどうかを確認するのに役立ちます。たとえば、 "asdf"と入力しないでください。 –

答えて

0

.........

ヘルプ "あなたは数が多すぎるよ" してみてください。

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 
0
If Val(TextBox1.Text) > Val(TextBox2.Text) Then 
     MsgBox("You're number is too high") 
    Else 
     MsgBox("ok") 
    End If 

あなたは数字のように見える数値や文字列を比較しようとしている

関連する問題