1.提示三次输入错误密码,自动退出程序
Private Sub cmdOK_Click()
Dim txtSQL As String
Dim mrc As ADODB.Recordset
Dim MsgText As String
UserName = ""
If Trim(txtUserName.Text = "") Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
txtUserName.SetFocus
Else
txtSQL = "select * from user_Info where user_ID = '" & txtUserName.Text & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.EOF Then
miCount = miCount + 1
If miCount = 1 Then
MsgBox "用户名错误,您还有两次机会!", vbOKOnly + vbExclamation, "警告"
txtUserName.SetFocus
Exit Sub
End If
If miCount = 2 Then
MsgBox "用户名错误,您还有一次机会!", vbOKOnly + vbExclamation, "警告"
txtUserName.SetFocus
Exit Sub
End If
If miCount = 3 Then
MsgBox "用户名错误,即将退出系统!", vbOKOnly + vbExclamation, "警告"
End
End If
Else
If Trim(mrc.Fields(1)) = Trim(txtPassWord.Text) Then
OK = True
mrc.Close
Me.Hide
UserName = Trim(txtUserName.Text)
FrmMain.Show
Else
miCount = miCount + 1
If miCount = 1 Then
MsgBox "密码错误,您还有两次机会!", vbOKOnly + vbExclamation, "警告"
txtPassWord.SetFocus
Exit Sub
End If
If miCount = 2 Then
MsgBox "密码错误,您还有一次机会!", vbOKOnly + vbExclamation, "警告"
txtPassWord.SetFocus
Exit Sub
End If
If miCount = 3 Then
MsgBox "密码错误,即将退出系统!", vbOKOnly + vbExclamation, "警告"
End
End If
End If
End If
End If
End Sub
**
2.修改各个文本框的输入字符的长度
**
通过修改属性的中的Maxlengh来实现
3.所有的姓名文本框均要限制只能添加汉字
实现代码:
Private Sub txtSID_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case Is < 0, &H20, &H8
Case Else
KeyAscii = 0
MsgBox “姓名只能输入汉字”
End Select
End Sub
4.所有班号,教室,成绩,电话都限制只能添加数字
If KeyAscii >= 48 And KeyAscii <= 57 Or KeyAscii = 8 Then
Else
KeyAscii = 0
MsgBox "只能输入数字!"
End If
5.限制输入非法字符
实现代码:
If ((KeyAscii >= 48 And KeyAscii <= 57) Or (KeyAscii >= 65 And KeyAscii <= 90) Or _
(KeyAscii >= 97 And KeyAscii <= 122) Or (KeyAscii = 8)) = False Then
KeyAscii = 0
MsgBox "禁止输入非法字符!", vbOKOnly, "警告"
End If