学生信息管理系统之ASCII问题汇总

来源:互联网 发布:数据库软件排行 编辑:程序博客网 时间:2024/05/22 06:27

前言
学生信息管理的优化阶段,需要注意很多由ASCII限制字符的问题,我汇总了一下。

首先附上一张ASCII对照表:


主要内容

1、登录界面的用户名禁止输入特殊字符

Private Sub txtusername_KeyPress(KeyAscii As Integer)    If KeyAscii = 8 Then Exit Sub        If (KeyAscii >= 0 And KeyAscii <= 47) Or (KeyAscii >= 58 And KeyAscii <= 64) Or (KeyAscii >= 91 And KeyAscii <= 96) Or (KeyAscii >= 123 And KeyAscii <= 127) Then KeyAscii = 0    End Sub


2、文本框中只允许输入数字
(1)设置属性:text属性中的maxlength限制输入最大字符数
(2)添加代码:禁止非数字的输入

Private Sub txtSID_KeyPress(KeyAscii As Integer)        If KeyAscii = 8 Then Exit Sub         'backspace可用    Select Case KeyAscii          Case 48 To 57, 13              '允许输入数字,回车可用        Case Else          KeyAscii = 0      End Select  End Sub


3、comboBox控件:不能自行输入,只能下拉选择
(1)设置属性:comboBox的style设置为2-DropdownList
(2)添加代码:combox的style设置为0-dropdown combo

private sub comboBox_keyPress(keyAscii as integer)        keyAscii=0End Sub

4、文本框中只允许输入文本

Private Sub txtName_KeyPress(KeyAscii As Integer)         If (KeyAscii < 0) Or (KeyAscii >= 65 And KeyAscii <= 90) Or(KeyAscii >= 97 And KeyAscii <= 122) Or (KeyAscii = 8) Then         Else             MsgBox "姓名由字母和汉字组成", vbOKOnly,"提示"             KeyAscii = 0             txtName.SelStart = 0             txtName.SelLength = Len(txtName.Text)         End If  End Sub