I'm making a calculator in VB, but I'm stuck with trying to make the textbox only receive floats, I can do it by having the textbox be cleared after every letter is put in, but that's quite a lot of overkill, I've added my code in, I hope you can help me ^.^
Private Sub Button1_TxtChng(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox1.KeyDown, TextBox2.KeyDown
Dim num1, num2 As String
num1 = TextBox1.Text
num2 = TextBox2.Text
If IsNumeric(TextBox1.Text) Then
'The compare code should be a function'
If num1 = num2 Then
Me.Label1.BackColor = Color.Orange
ElseIf num1 < num2 Then
Me.Label1.BackColor = Color.Red
Else
Me.Label1.BackColor = Color.LightGreen
End If
Else
TextBox1.Clear()
End If
If IsNumeric(TextBox2.Text) Then
'The compare code should be a function'
If num1 = num2 Then
Me.Label1.BackColor = Color.Orange
ElseIf num1 < num2 Then
Me.Label1.BackColor = Color.Red
Else
Me.Label1.BackColor = Color.LightGreen
End If
Else
TextBox2.Clear()
End If
End Sub