No.1添加学籍信息是增加日历功能
注意:同理MonthView2
No.2添加学籍信息增加日历功能且入学日期大于出生日期
Private Sub DTPicker1_CallbackKeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer, ByVal CallbackField As String, CallbackDate As Date)
txtRudate.Text = DTPicker1.Value '所选日期赋予入学日期文本框
End Sub
Private Sub DTPicker1_Change()
txtRudate.Text = DTPicker1.Value '将更改后的入学日期赋予文本框
If DTPicker2.Value >= DTPicker1.Value Then
MsgBox "入学日期大于出生日期,请重新选择!", vbOKOnly + vbExclamation, "警告"
txtRudate.Text = ""
End If
End Sub
Private Sub DTPicker2_CallbackKeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer, ByVal CallbackField As String, CallbackDate As Date)
txtBorndate.Text = DTPicker2.Value '所选日期赋予出生日期文本框
End Sub
Private Sub DTPicker2_Change()
txtBorndate.Text = DTPicker2.Value '将更改日期赋予文本框
If DTPicker1.Value <= DTPicker2.Value Then
MsgBox "入学日期大于出生日期,请重新选择!", vbOKOnly + vbExclamation, "警告"
txtBorndate.Text = ""
End If
End Sub
注意:要想两个控件都能使用,需对两个控件的代码进行设置,若设置一个,另一个不起作用
No.3字符的限制
KeyPress事件,表示vb中的键盘事件,KeyAscii表示按下的键值。通过IF 语句设置KeyAscii的数值来控制文本框中能输入文字或者数字。
1、在文本框中限制输入特殊字符
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
Dim cTemp As String
cTemp = "`~!@#$%^&*()-=_+[]{};:'\|<>/?.‘“”’、,。——+()《》?,~·……¥!:;【】" & """ '禁止输入特殊的字符"
If InStr(1, cTemp, Chr(KeyAscii)) <> 0 Then KeyAscii = 0
End Sub
2、在文本框中只能输入数字
1)
Private Sub txtSID_KeyPress(KeyAscii As Integer) If KeyAscii = 8 Then Exit Sub If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0 '这条语句用来判断输入的字符是否在0-9的范围,如果不在这个范围,就把这个输入的字符屏蔽掉 End Sub2)
Private Sub txtTel_KeyPress(KeyAscii As Integer) Select Case KeyAscii Case 48 To 57 Case 8 Case Else KeyAscii = 0 MsgBox "请输入数字", vbOKOnly + vbExclamation, "提示" End Select End Sub
3、在文本框中只能输入汉字
Private Sub txtName_KeyPress(KeyAscii As Integer)
If KeyAscii >= -20319 And KeyAscii <= -3652 Or KeyAscii = 8 Then
Else
KeyAscii = 0
End If
End Sub
4、在VB中有个MaxLength属性可以限制文本框的输入长度,对英文字母和数字有用,但对中文来讲,使用效果则不相同。
例如:数据库中设定数据长度为10,MaxLength属性值设为10,在VB中输入了9个中
文,此时仍然可以继续输入1个字,但保存到数据库中时,则需要20个字节来保存,
这时数据库会提示出错。
为了解决这个问题,需要做如下处理:
Private Sub Text1_Change(Index As Integer)
Static mTestTemp As String
Dim t1 As TextBox
Dim i As Integer
Set t1 = Text1(0)
If LenB(StrConv(t1.Text, vbFromUnicode)) > t1.MaxLength Then
i = t1.SelStart
t1.Text = mTestTemp
If i > 0 Then t1.SelStart = i - 1
Else
mTestTemp = t1.Text
End If
End Sub
No.4窗体大小的调整
每个窗体的大小是固定不变的有的不能正常显示出我们所需要的所有内容,而在属性中改变后运行无法改变。
解决方法:在每个窗体中的Form_Load事件规定适合窗体的宽高
No.5限制学号框位数
方案一:代码
方案二:控件属性