一、添加出生日期和入学日期的文本框在获得焦点的时候(还没填),弹窗提示,输入“yyyy-mm-dd”格式的日期,信息全部添加完成后,点击确定以添加学生档案,如果入学日期<=出生日期,弹窗并提示用户返回修改。
'定义这两个变量,后期进行输入出生和入学时期的比较
Dim borndate As Date
Dim getdate As Date
'开始比较两个框输入的是否符合逻辑关系
borndate = Trim(txtBorndate.Text)
getdate = Trim(txtRudate.Text)
If getdate <= borndateThen
MsgBox "入学时间不能小于出生时间,不合逻辑(⊙o⊙)!请重新输入",vbOKOnly + vbInformation, "提示"
txtRudate.SetFocus
Exit Sub
End If
二、将VB窗体手动改为默认大小。
将窗体的borderstyle属性改为1-FixedSingle ,然后手动调节大小。
三、VB中combo box 控件禁止输入数据。
解决方案:将combobox 控件style属性改为2-Drop List
四、Text中限制只能输入数字。例如:电话号码输入框
Private Sub txtTel_KeyPress(KeyAscii As Integer)
If KeyAscii < 47 Or KeyAscii > 58 or KeyAscii=8 Then
KeyAscii = 0
End If
End Sub
五、为日期Text窗口添加日历控件。
添加 部件:Microsoft Windows Common Controls-2 6.0
添加:DTPicker控件或MonthView控件都可以的
Private Sub MonthView1_DateClick(ByVal DateClickedAs Date)
txtBorndate.Text = MonthView1.Year &"-" & MonthView1.Month & "-" & MonthView1.Day
MonthView1.Visible = False
End Sub
Private Sub MonthView2_DateClick(ByVal DateClicked As Date)
txtRudate.Text = MonthView2.Year &"-" & MonthView2.Month & "-" & MonthView2.Day
MonthView2.Visible = False
End Sub
Private Sub Form_Load() '初始化内容
MonthView2.Visible = False
MonthView1.Visible = False
Private Sub txtBorndate__Click()
MonthView1.Visible = True
End Sub
Private Sub txtRudate__Click()
MonthView2.Visible = True
End Sub
六、修改密码处的优化。
修改前后对比情况
实现调用数据库显示当前用户名的代码:
Private Sub Form_Load()
Dim txtSQL, MsgText As String
Dim mrc As ADODB.Recordset
Dim name As String
Text2.Text = ""
Text1(1).Text = ""
Text1(2).Text = ""
txtSQL = "select * fromuser_Info where user_ID = '" & UserName & "' "
Set mrc = ExecuteSQL(txtSQL, MsgText)
name = Trim(mrc.Fields(0))
Label4.Caption = "当前用户名称为:"& name
End Sub
实现输入原密码确认的代码:
Private Sub cmdOK_Click()
txtSQL = "select * from user_Infowhere user_ID = '" & UserName & "' "
Set mrc = ExecuteSQL(txtSQL, MsgText)
If Trim(Text2.Text) = Trim(mrc.Fields(1))Then '原密码的验证
Else
MsgBox "原密码输入错误,请重新输入!", vbOKOnly + vbExclamation, "警告"
End If
micount = micount + 1
If micount = 3 Then
MsgBox "三次机会使用完,请重新登录!", vbOKOnly + vbExclamation, "警告"
Me.Hide
End If
Exit Sub 三次密码不对就等重新登陆,保护账户安全
七、设置年级课程:避免同年级一个课程被重复选中。
Private Sub cmdAdd_Click()
If listAllcourse.ListIndex <> -1Then
listSelectcourse.AddItemlistAllcourse.List(listAllcourse.ListIndex)
End If
End Sub 修改前
Private Sub cmdAdd_Click()
Dim I As Integer
If listAllcourse.ListIndex <> -1Then
If listSelectcourse.ListCount = 0 Then
listSelectcourse.AddItem listAllcourse.List(listAllcourse.ListIndex)
End If
For I = 0 To listSelectcourse.ListCount- 1
If listSelectcourse.List(I) =listAllcourse.List(listAllcourse.ListIndex) Then
Exit Sub
End If
Next
listSelectcourse.AddItemlistAllcourse.List(listAllcourse.ListIndex) 修改后
End If
End Sub
八、查询窗体中MSHFlexGrid,字段名在第一行显示。
将.Rows = .Rows + 1去除,避免空行的产生。
Private Sub Form_Load()
With myflexgrid
.CellAlignment = 4 'flexAlignCenter
.TextMatrix(0, 0) = "学号"
.TextMatrix(0, 1) = "姓名"
.TextMatrix(0, 2) = "性别"
.TextMatrix(0, 3) = "出生日期"
.TextMatrix(0, 4) = "班号"
.TextMatrix(0, 5) = "联系电话"
.TextMatrix(0, 6) = "入校日期"
.TextMatrix(0, 7) = "家庭住址"
End With
End Sub '就是将(1,0).... 左边的1都改为0