Const xStr As String = "0123456789"
'先声明一个常量,并把你想禁用或允许输入的内容赋值给它
Private Sub Text1_KeyPress(KeyAscii As Integer)
'只能输入数字
KeyAscii = IIf(InStr(xStr & Chr(8), Chr(KeyAscii)), KeyAscii, 0)
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
'只能输入数字以外的字符
KeyAscii = IIf(InStr(xStr, Chr(KeyAscii)), 0, KeyAscii)
End Sub |