Private Sub txtclassno_KeyPress(KeyAscii As Integer)
If KeyAscii >= 33 Then
If KeyAscii <= vbKey9 And KeyAscii >= vbKey0 Then
Else
KeyAscii = 0
MsgBox "请输入数字!"
End If
End If
End Sub
二,限制不能输入数字
Private Sub Txtname_KeyPress(KeyAscii As Integer) '姓名不能输入数字
If (KeyAscii >= 48 And KeyAscii <= 57) Then
MsgBox "不允许输入数字", vbOKOnly + vbExclamation, "警告"
KeyAscii = 0 '键盘不能用
End If
End Sub
三,复选框只能选择,禁止输入
Private Sub comboSex_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub
Private Sub listAllcourse_Click()
Dim selectcourse As Integer
Dim i As Integer '定义两个整形变量
Dim j As Integer
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, "提示"
Exit Sub
End If
Next j
Next i
End If
Next selectcourse
End Sub