【前言】
经过将近一个月的时间,学生信息管理系统完成了,在这其中学到了不少。
【正文】
在刚敲完学生时,有各种各样的错误,需要一点一点的优化,以下是我优化的一部分:
1.限制用户名和密码的长度:
属性中,MaxLength=8
2.只能输入数字:
If KeyAscii = 8 Then Exit Sub
If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0
3.只能输入汉字:
If KeyAscii >= -20319 And KeyAscii <= -3652 Or KeyAscii = 8 Then
Else
KeyAscii = 0
End If
4.输入汉字和字母:
If (KeyAscii < 0) Or (KeyAscii >= 65 And KeyAscii <= 90) Or (KeyAscii >= 97 And KeyAscii <= 122) Or (KeyAscii = 8) Then
Else
MsgBox "姓名由字母和汉字组成", vbOKOnly + vbExclamation, "警告"
KeyAscii = 0
txtName.SelStart = 0
txtName.SelLength = Len(txtName.Text)
5.限制特殊符号的输入:
Dim cTemp As String
cTemp = "`~!@#$%^&*()-=_+[]{};:'\|<>/?.‘“”’、,。——+()《》?,~·……¥!:;【】" & """ '禁止输入特殊的字符"
If InStr(1, cTemp, Chr(KeyAscii)) <> 0 Then KeyAscii = 0
6.Combox框只允许下拉选择,不允许输入:
将Style属性设置为0,然后写代码:
Private Sub comboBorndate_KeyPress(KeyAscii As Integer)
KeyAscii = 0 禁止输入
End Sub
Private Sub comboRudate_KeyPress(KeyAscii As Integer)
KeyAscii = 0 禁止输入
End Sub
7.不能重复添加成绩信息:(班级和课程也类似)
txtSQL = "select * from result_Info where exam_No = '" & comboExamtype.Text & "' and student_ID = '" & comboSID.Text & "' and course_Name = '" & comboCourse.Text & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.EOF = False Then
MsgBox "有相同纪录,请重新输入信息!", vbOKOnly + vbExclamation, "警告"
mrc.Close
Else
……
8.出生日期、入校日期和当前日期的关系
If comboBorndate > Date Then
MsgBox "出生日期不能大于当前日期,请重新输入!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
If comboRudate > Date Then
MsgBox "入校日期不能大于当前日期,请重新输入!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
If comboBorndate > comboRudate Then
MsgBox "出生日期不能大于入校日期,请重新输入!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If