学生信息管理系统优化篇

这个模块没有了实时错误,但是有的地方还需要优化,因此,我们对这个模块进行优化。
1. 输入日期麻烦,用DTPicker控件代替
由于我们输入日期麻烦,而且由于格式限制,经常错误,因此我们可以用一个DTPicker控件代替,具体的添加的方法是单击工程,部件,在控件中选中Microsoft Windows Common Controls-2.6.0,之后直接添加即可。
在这里插入图片描述
2.ComboBox控件只能选择,不能键盘输入
两只方法:一是在属性窗口对ComboBox控件的style属性选择2—DropDown List;二是在代码中对ComboBox的KeyPress事件进行编辑

Private Sub comboSex_KeyPress(KeyAscii As Integer)
    KeyAscii = 0
End Sub

一般选择第二种方法,当选择第一种方法时,在有的程序中达不到想要的结果,例如本例中当所有记录删除完时,让界面清零,如果选第一种方法,加载的界面有关ComboBox控件的内容不会删除,会保留最后的记录。
3. 入校日期超过出生日期

用指针进行判断,代码如下:

 Dim born As Date
 Dim ru As Date
 born = Trim(txtBorndate.Value)
    ru = Trim(txtRudate.Value)
    If ru <= born Then
        MsgBox "入校日期要超过出生日期!!!", vbOKOnly + vbExclamation, "警告"
        txtBorndate.SetFocus
        Exit Sub
    End If

4. Vb中无法进行选择语句行的顺序判断和对Msgbox弹出框的编辑
本来是想对MsgBox弹出的对话框的按钮进行编辑,但是发现不行,因为其按钮没有实体,没办法对其写程序
5.显示字符串长度
一种是在属性窗口对控件的MaxLength属性进行编辑,二是在代码中对MaxLength属性进行编辑。
6.限制字符出串类型(在KeyPress事件中编辑)
1.只输入数字和删除键

If KeyAscii <> 8 And (KeyAscii < 48 Or KeyAscii > 57) Then
     KeyAscii = 0
     end if

2.只输入数字和小数和删除键

If KeyAscii <> Asc(".") And (KeyAscii <> 8) And (KeyAscii < Asc("0") Or KeyAscii > Asc("9")) Then
    KeyAscii = 0
    End If

3.限制文本框输入内容的数值范围

If Val(txtClassno.Text) > 2147483647 Or Val(txtClassno.Text) < 1Then
            MsgBox "输入数值在1到2147483647范围内"
            txtClassno.SetFocus
            Exit Sub```
4.文本框内只能输入文字及删除键

If KeyAscii >= -20319 And KeyAscii <= -3652 Or KeyAscii = 8 Then
Else
KeyAscii = 0
End If

5.输入数字和英文字母

If ((KeyAscii >= 48 And KeyAscii <= 57) Or (KeyAscii >= 65 And KeyAscii <= 90) Or (KeyAscii >= 97 And KeyAscii <= 122)) = False Then
KeyAscii = 0
End If

6.只能输入数字和文字

If ((KeyAscii <= 57 And KeyAscii >= 48) Or (KeyAscii <= -3652 And KeyAscii >= -20319) Or KeyAscii = 8) = False Then
KeyAscii = 0
End If

7.只能输入文字,英文和空格

If ((KeyAscii <= -3652 And KeyAscii >= -20319) Or (KeyAscii >= 65 And KeyAscii <= 90) Or (KeyAscii >= 97 And KeyAscii <= 122) Or KeyAscii = 32 Or KeyAscii = 8) = False Then
KeyAscii = 0
End If

**7.退出系统时提示**
代码如下:

Dim str As VbMsgBoxResult
str = MsgBox(“是否退出系统?”, vbOKCancel, “警告”)
If str = vbOK Then
Unload Me
End If

**8.添加快捷键enter键**
首先设置Tabindex属性
在添加代码如下:

if keyascii=13 then
控件.setfocus
end if


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 16
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值