学生系统的各种限制

1.限制不准复制粘贴
Private Sub txtCourseno_KeyDown(KeyCode As Integer, Shift As Integer)
If Shift = 2 Then
MsgBox “不准复制粘贴”, vbOKOnly + vbExclamation, “提示”
End If
End Sub
Private Sub txtCourseno_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then MsgBox “不准粘贴复制”, vbOKOnly + vbExclamation, “警告”
End Sub
2.限制只能数字字母和退格键
Private Sub txtCourseno_KeyPress(KeyAscii As Integer)
If KeyAscii = 8 Then
ElseIf KeyAscii < 48 Or (KeyAscii > 57 And KeyAscii < 64) Or (KeyAscii > 91 And KeyAscii < 96) Or KeyAscii > 122 Then KeyAscii = 0
End If
End Sub
3.限制特殊字符、数字、空格,只能输入汉字和字母
Private Sub txtDirector_KeyPress(KeyAscii As Integer)
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, “提示”
End If
End Sub
4.只能输入数字字母汉字退格
Private Sub txtCoursename_KeyPress(KeyAscii As Integer)
If KeyAscii >= -20319 And KeyAscii <= -3652 Or KeyAscii = 8 Then
ElseIf KeyAscii < 48 Or (KeyAscii > 57 And KeyAscii < 64) Or (KeyAscii > 91 And KeyAscii < 96) Or KeyAscii > 122 Then KeyAscii = 0
End If
'限制字数
If Len(txtCoursename) > 18 Then
KeyAscii = 0
MsgBox “字数超出”, vbOKOnly + vbExclamation, “提示”
End If

End Sub
5.添加成绩信息限制
Private Sub txtResult_Change()
On Error Resume Next
If Val(Trim(txtResult.Text)) > 150 Then
MsgBox “输入数字过大,请重新输入”, vbOKOnly + vbExclamation, “提示”
txtResult.Text = “”
End If
End Sub
6.限制家庭住址不能输入特殊字符
Private Sub txtAddress_KeyPress(KeyAscii As Integer)
Dim cTemp As String
cTemp = “`!@#$%^&*()-=_+[]{};:’|<>".‘“”’、,。——+()《》?,·……¥!:;【】” & “”" '禁止输入特殊的字符"
If InStr(1, cTemp, Chr(KeyAscii)) <> 0 Then
KeyAscii = 0
MsgBox “家庭住址不可为特殊字符”, vbOKOnly + vbExclamation, “提示”
End If
End Sub

猜你喜欢

转载自blog.csdn.net/qq_44685392/article/details/103260680