学生信息管理系统优化(一)

一、限制文本框只能输入特定内容 本质上都是对ASCII表的应用 以限制只能输入汉字和字母为例
Private Sub txtDirector_KeyPress(KeyAscii As Integer)
'只能输入汉字和字母
 If KeyAscii >= -20319 And KeyAscii <= -3652 Or KeyAscii = 8 Or KeyAscii >= 65 And KeyAscii <= 90 Or KeyAscii >= 97 And KeyAscii <= 122 Then
    Else
    KeyAscii = 0
    MsgBox "请输入汉字,或字母!", vbOKOnly + vbExclamation, "警告"
    txtDirector.SetFocus
    txtDirector = ""
 End If
End Sub

汉字范围时-20319到-3652 backspace键是8 大小写字母是65-90 97-122

二、日历 DTPicker 的使用

1.选择使用
引用Microsoft Windows Common Controls-2.6在这里插入图片描述
可在属性界面Format 更改格式
在这里插入图片描述
一般默认为1
选择为3时需提前设置CustomFormat 属性

2.出生时间必须早于入校时间,出生时间早于系统时间

具体代码

'判断出生日期早于入校日期

    If DTPicker2.Value > DTPicker1.Value Then
        MsgBox "出生日期必须早于入校时间", vbOKOnly + vbExclamation, "警告"
        Exit Sub
    End If
'判断出生日期早于系统时间
    If DTPicker1.Value > Date Then
        MsgBox "出生时间必须早于系统时间", vbOKOnly + vbExclamation, "警告"
        Exit Sub
三、点击课程设置课程重复问题
Private Sub cmdSet_Click()
    Dim mrc As ADODB.Recordset
    Dim txtSQL As String
    Dim MsgText As String
    Dim a As Integer
    Dim b As Integer
    listselectcourse.Clear
    listallcourse.Enabled = True
    listselectcourse.Enabled = True
    cmdModify.Enabled = True
    txtSQL = "select * from course_Info "
    Set mrc = ExecuteSQL(txtSQL, MsgText)
'判断是否到最后一条记录
	 While (mrc.EOF = False)
'添加内容到列表框中
    listallcourse.AddItem mrc.Fields(1)
    mrc.MoveNext
	Wend
'消除课程重复
For a = 0 To listallcourse.ListCount - 1
    For b = a + 1 To listallcourse.ListCount
        If listallcourse.List(b) = listallcourse.List(a) Then
            listallcourse.RemoveItem b
        End If
    Next b
Next a
	mrc.Close
    flagset = True
End Sub
发布了35 篇原创文章 · 获赞 1 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/wangwei021933/article/details/100123036