Q:

One Textbox Value Greater then other, Avoid and Beep

I have two Textboxes in Visual Basic 2010
Textbox1
Textbox2
Now I want that if user enter value(integer) in Textbox2, if the value in Textbox2 is Greater than Textbox1, so this will do a beep and also avoid him to do like this
Example: If User write 5 in Textbox1 and now he is writing 8 in Textbox2 so as 8 is grater than 5, so i want that Textbox2 ignore with a beep.
I have this code but this is not working, please if some one help me:

Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress

    Dim valx1 As Integer
    Dim valx2 As Integer

    valx1 = (Val(TextBox1.Text))
    valx2 = (Val(TextBox2.Text))

    If (valx1) > (valx2) Then
        Beep()
        e.Handled = True
    End If

End Sub

A:

This code will suits your requirement, By the way using a beeb sound for alerting the user, will make him/her disturbed.
 Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress

   if val(TextBox1.Text.trim) > val(TextBox2.Text.trim & e.keychar) then
          Beep()
          e.Handled = True
    end if

End Sub

