给你个函数
Public Function ValiText(KeyIn As Integer, ValidateString As String, Editable As Boolean) As Integer '密码设置
Dim ValidateList As String
Dim KeyOut As Integer
If Editable = True Then
ValidateList = UCase(ValidateString) & Chr(8)
Else
ValidateList = UCase(ValidateString)
End If
If InStr(1, ValidateList, UCase(Chr(KeyIn)), 1) > 0 Then
KeyOut = KeyIn
Else
KeyOut = 0
Beep
End If
ValiText = KeyOut
End Function
然后再text的keypress事件中
KeyAscii = ValiText(KeyAscii, "0123456789.", True)
其中上面的式子中" "可以填入你限制的字符等
此函数通用。这里就只能是数字和小数点