-
HI.
Ok let's say i have the textbox and my code is:
Code:
Private Sub txt1_KeyPress(KeyAscii As Integer)
If KeyAscii > 57 Or KeyAscii = 32 Or KeyAscii = 33 Or KeyAscii = 35 Or KeyAscii = 36 Or KeyAscii = 37 Or KeyAscii = 38 Or KeyAscii = 40 Or KeyAscii = 41 Or KeyAscii = 42 Or KeyAscii = 43 Or KeyAscii = 44 Or KeyAscii = 45 Or KeyAscii = 47 Then
KeyAscii = 0
End If
End Sub
This code prevents text writing in the textbox.
And the question Is: How can i prevent
writing of second dot?
for egzample 2.1133...
or 654.15.
-
Use the InStrRev function and search for
a "." in the text.
-
Private Sub txt1_KeyPress(KeyAscii As Integer)
' Allow only "(34), '(39), .(46), 0~9(48~57)
' I also allow "Backspace"(8)
If KeyAscii <> 34 And KeyAscii <> 39 And KeyAscii <> 46 _
And KeyAscii <> 8 And Not (KeyAscii > 47 And KeyAscii < 58) Then
KeyAscii = 0
ElseIf KeyAscii = 46 Then
If InStr(1, txt1, ".") > 0 Then KeyAscii = 0
End If
End Sub
HTH
Joon
-
That's a bit complicated but i'll try to understand
thanx
-casparas