Select Case KeyAscii
Case 48 To 57
Case 46
Case 8
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
Dim s As String, SearchChar As String
Dim i As Integer
s = Text1.Text
Dim x As Integer
SearchChar = "."
x = InStr(1, s, SearchChar, 1)
If x = 0 Then
If Len(s) > 2 Then
Text1.Text = Mid(s, 1, 2)
End If
ElseIf x <= 3 Then
If x < Len(s) Then
Text1.Text = Left(Text1.Text, x - 1) + "." + Right(Text1.Text, Len(Text1.Text) - x)
End If
If Len(Right(s, Len(s) - x)) > 2 Then
Text1.Text = Left(Text1.Text, x - 1) + "." + Mid(Text1.Text, x + 1, 2)
End If
ElseIf x > 3 Then
Text1.Text = Mid(s, 1, 2)
End If
End Sub
L = InStr(1, Text1.Text, ".")
If L > 1 And L + 2 < Len(Text1.Text) Then
Text1.Text = Left(Text1.Text, L + 2)
End If
If Text1.Text <> "" Then
If (Asc(Right(Text1.Text, 1)) < 48 Or Asc(Right(Text1.Text, 1)) > 57) And Asc(Right(Text1.Text, 1)) <> 46 Then
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End If
End If
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (Len(Text1.Text) = 0) And (KeyAscii = 46) Then KeyAscii = 0
If (KeyAscii = 46) And (InStr(Text1.Text, ".")) Then KeyAscii = 0
If (KeyAscii < 48 Or KeyAscii > 57) And (KeyAscii <> 46) Then KeyAscii = 0
If (InStr(Text1.Text, ".")) Then
If (Len(Text1.Text) - InStr(Text1.Text, ".")) >= 2 Then KeyAscii = 0
Else
If (Len(Text1.Text) = 2) And (KeyAscii <> 46) Then KeyAscii = 0
End If
End Sub