您的位置:首页 > 其它

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

2017-08-17 18:39 344 查看
前言
学生信息管理的优化阶段,需要注意很多由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 comboprivate sub comboBox_keyPress(keyAscii as integer)
keyAscii=0
End 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: