If KeyAscii < 48 Or KeyAscii > 57 Then If KeyAscii = 46 Then If Text1.Text = "" Or InStr(1, Text1.Text, ".") <> 0 Then KeyAscii = 0 Else KeyAscii = 46 End If Else KeyAscii = 0 End If End If
End Sub
山城夏秋
2024-05-16 20:33:55
VB妮可 的代码不错,不过找出点小问题-----不能退格
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then If KeyAscii = 46 Then If Text1.Text = "" Or InStr(1, Text1.Text, ".") <> 0 Then KeyAscii = 0 Else KeyAscii = 46 End If Else KeyAscii = 0 End If End If
End Sub
满栀
2024-05-16 16:18:30
Private Sub Text1_KeyPress(KeyAscii As Integer) If (KeyAscii < 46 Or KeyAscii > 57 or KeyAscii = 47)and KeyAscii<>8 Then KeyAscii = 0 End If End Sub 这样就可以了,可以用退格,KeyAscii为47是"\"符。
怎忘
2024-05-16 13:01:40
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer) If Right(Text1.Text, 1) = "." Then Text1.Text = Val(Text1.Text) & "." Else Text1.Text = Val(Text1.Text) End If End Sub '简单有效,可以试试。