内联代码片
。
限制教室文本框只能输入汉字和数字
If ((KeyAscii <= 57 And KeyAscii >= 48) Or (KeyAscii <= -3652 And KeyAscii >= -20319) Or KeyAscii = 8) = False Then KeyAscii = 0
txtClassroom.MaxLength = 15
End Sub
限制特殊字符、数字、空格,只能输入汉字和字母
。
Select Case KeyAscii
Case -20319 To -3652
Case 48 To 57
Case 65 To 90
Case 97 To 122
Case 8
Case Else
KeyAscii = 0
End Select
不能输入特殊字符`。
If KeyAscii < 0 Or KeyAscii = 8 Or KeyAscii = 13 Then
ElseIf Not Chr(KeyAscii) Like "[a-zA-Z]" Then
KeyAscii = 0
MsgBox "请输入汉字或字母", vbOKOnly + vbExclamation, "提示"
txtDirector.MaxLength = 20
End If
禁止复制粘贴
If Shift = 2 Then
MsgBox "不准复制粘贴", vbOKOnly + vbExclamation, "提示"
End If
限制只能数字和退格键
Select Case KeyAscii
Case 48 To 57
Case 8
Case Else
KeyAscii = 0
MsgBox “请输入数字”, vbOKOnly + vbExclamation, “提示”
txtClassno.Text = “”
只能输入汉字
If KeyAscii >= -20319 And KeyAscii <= -3652 Or KeyAscii = 8 Then
Else
KeyAscii = 0
MsgBox “请输入汉字!”, vbOKOnly + vbExclamation, “提示”
txtCoursedes.SetFocus
txtCoursedes.MaxLength = 20
End If
下面展示一些 `内联代码片`。
If Len(txtCoursename) > 10 Then
KeyAscii = 0
MsgBox “字数超出”, vbOKOnly + vbExclamation, “提示”
End If
下面展示一些 `内联代码片`。
Dim borndate As Date
Dim getdate As Date '定义变量
'borndate = Trim(dtpborn.Text)
'getdate = Trim(dtpborn.Text)
If getdate <= borndate Then '进行比较
MsgBox “入学时间不能早于出生时间,请重新输入”, vbOKOnly + vbInformation, “警告”
dtpborn.SetFocus
Exit Sub