一:限制输入
只能输入数字:
If KeyAscii >= 48 And KeyAscii <= 57 Or KeyAscii = 8 _
Or KeyAscii = 13 Then
Else
If KeyAscii = 32 Then
MsgBox "不能输入空格!", vbOKOnly + vbExclamation, "警告"
KeyAscii = 0
Else
MsgBox "对不起,班号为数字!", vbOKOnly + vbExclamation, "警告"
KeyAscii = 0
txtClassno.Text = ""
txtClassno.SetFocus
只能输入文字:
If KeyAscii < 0 Or KeyAscii = 8 Or KeyAscii = 13 Then
Else
If KeyAscii = 32 Then
MsgBox "不能输入空格!", vbOKOnly + vbExclamation, "警告"
KeyAscii = 0
Else
MsgBox "对不起,姓名为汉字!", vbOKOnly + vbExclamation, "警告"
KeyAscii = 0
txtName.Text = ""
txtName.SetFocus
限制下拉框输入字符:
KeyAscii = 0
combobox可以使用属性限制(style选择2即可)。
二:日期无需手动输入
使用DTPicker控件
添加相应的代码。
入学日期不能超出当前日期。
If getdate > Date Then
MsgBox "入学日期不能早于当前日期", vbOKOnly + vbExclamation, "警告"
入学日期不小于出生日期
If getdate < borndate Then
MsgBox "入学日期不能小于出生日期", vbOKOnly + vbExclamation, "警告"
出生日期不大于当前日期
If borndate > Date Then
MsgBox "出生时间不能大于当前时间", vbOKOnly + vbExclamation, "警告"
三:限制电话为11位
If Len(txtTel) < 11 Then
MsgBox "联系电话为11位,请检查", vbOKOnly + vbExclamation, "警告"
四:不能重复添加课程
For selectcourse = 0 To listAllcourse.ListCount - 1
If listAllcourse.Selected(selectcourse) = True Then
listSelectcourse.AddItem listAllcourse.List(listAllcourse.ListIndex)
' 向listselectcourse列表中添加课程
For i = 0 To listSelectcourse.ListCount - 1
For j = i + 1 To listSelectcourse.ListCount
'判断在list列表中是否有相同的名称
If listSelectcourse.List(i) = listSelectcourse.List(j) Then
listSelectcourse.RemoveItem (j)
MsgBox "已添加此课程!", vbOKOnly + vbExclamation, "提示"