DiverDan
Contributor
I'm trying to eliminate multiple instances of dot and minus in a textbox. My code is obviously not working but is as follows:
How can I eliminate multiple instances of dot and minus?
Thanks
Visual Basic:
Private Sub tbTemperature_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tbTemperature.KeyPress
Dim i, charsInBox As Short
Dim charactor As String
charsInBox = Len(tbTemperature.Text)
If Not AscW(e.KeyChar) <= 47 And Not AscW(e.KeyChar) >= 58 Or AscW(e.KeyChar) = 8 Or AscW(e.KeyChar) = 46 Or Asc(e.KeyChar) = 45 Then
For i = 0 To charsInBox - 1
charactor = tbTemperature.Text.Substring(i, 1)
If charactor = "." Then e.Handled = True
If charactor = "-" Then e.Handled = True
Next
e.Handled = False
Else
e.Handled = True
End If
End Sub
How can I eliminate multiple instances of dot and minus?
Thanks
Last edited by a moderator: