Private Sub Text10_Change()
Dim a As String, x As String, Y As String, b As Integer, i As Integer
a = Text10.Text
b = Len(a)
x = a
Y = a
If b > 0 Then
For i = 1 To b
If Asc(Mid(x, i, 1)) < 48 Or Asc(Mid(x, i, 1)) > 57 Then
If b - i - 1 < 0 Then
Y = Left(a, b - 1)
ElseIf i = 1 Then
Y = Right(a, b - 1)
Else
Y = Left(a, i - 1) + Right(a, b - i)
End If
End If
Next i
End If
在text的keyPress事件中加入
If KeyAscii = vbKeyTab Or KeyAscii = vbKeyBack Then Exit Sub
Dim a As String
a = Chr(KeyAscii)
If IsNumeric(a) = False And a <> vbkeybackup Then KeyAscii = 0