跪求一段VB代码,textbox只能输入数字,小数点

来源:百度知道 编辑:UC知道 时间:2024/05/17 21:47:20

Private Sub Text1_KeyPress(KeyAscii As Integer)

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

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

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