1,452
社区成员
发帖
与我相关
我的任务
分享
'窗体上放 3 个 CheckBox,1 个 TextBox
Option Explicit
Private Sub Form_Load()
Check1.Caption = "字母"
Check2.Caption = "数字"
Check3.Caption = "汉字"
Text1 = vbNullString
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim bIsValid As Boolean
Select Case KeyAscii
Case vbKeyA To vbKeyZ, 97 To 122 '[A-Za-z]
bIsValid = Check1.Value
Case vbKey0 To vbKey9 '[0-9]
bIsValid = Check2.Value
Case Is < 0
bIsValid = Check3.Value
Case Else
End Select
If Not bIsValid Then
KeyAscii = 0
End If
End Sub