学生管理系统总结收获——限制字符
生活随笔
收集整理的這篇文章主要介紹了
学生管理系统总结收获——限制字符
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
一.ASCII碼——限制字符問(wèn)題
在敲學(xué)生的時(shí)候需要設(shè)置很多限制條件,比如限制字符,顯示數(shù)據(jù)類(lèi)型,限制字符長(zhǎng)度等等,其中有很多限制需要通過(guò)ASCII碼來(lái)進(jìn)行代碼編寫(xiě)限制,數(shù)不勝數(shù),小編至今還是有很多限制條件的ASCII 不知道,記是永遠(yuǎn)記不住的,未來(lái)用到的時(shí)候再多多補(bǔ)充啦。下面是小編在優(yōu)化學(xué)生時(shí)經(jīng)常用到的一些代碼限制條件,分享給大家。
1.文本框只能輸入漢字:
Private SubtxtDirector_KeyPress(KeyAscii As Integer)??If KeyAscii > 0 And KeyAscii <> 13And KeyAscii <> 8 Then KeyAscii = 0 End Sub或者: Private Sub txtusername_KeyPress(KeyAscii As Integer)If KeyAscii < 0 Or KeyAscii = 8 Or KeyAscii = 13 Then Exit SubKeyAscii = 0End Sub或者: Private Sub txtDirector_KeyPress(KeyAscii As Integer) If KeyAscii < 0 Or KeyAscii = 8 Then Exit Sub KeyAscii = 0 ‘不能輸入 End Sub2.只能輸入文字及刪除鍵:
Private Sub Text1_KeyPress(KeyAscii As Integer)If KeyAscii >= -20319 And KeyAscii <= -3652 Or KeyAscii = 8 ThenElseKeyAscii = 0End If End Sub3.限制只能輸入數(shù)字:
If KeyAscii = 8 Then Exit Sub If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 04.限制只能輸入數(shù)字和刪除鍵:
If KeyAscii <> 8 And (KeyAscii < 48 Or KeyAscii > 57) ThenKeyAscii = 0End if5.只能輸入數(shù)字和文字:
If ((KeyAscii <= 57 And KeyAscii >= 48) Or (KeyAscii <= -3652 And KeyAscii >= -20319) Or KeyAscii = 8) = False Then KeyAscii = 06.只能輸入數(shù)字和英文字母:
Private Sub Text1_KeyPress(KeyAscii As Integer)If ((KeyAscii >= 48 And KeyAscii <= 57) Or (KeyAscii >= 65 And KeyAscii <= 90) Or (KeyAscii >= 97 And KeyAscii <= 122)) = False Then KeyAscii = 0 End Sub7.只輸入數(shù)字、小數(shù)和刪除鍵:
If KeyAscii <> Asc(".") And (KeyAscii <> 8) And (KeyAscii < Asc("0") Or KeyAscii > Asc("9")) ThenKeyAscii = 0End If'添加成績(jī)窗體限制成績(jī): (1)限制添加成績(jī)窗體只能輸入數(shù)字且大于0小于150且可以使用退格鍵 If KeyAscii = 8 Then Exit SubIf KeyAscii < 48 Or KeyAscii > 57 ThenKeyAscii = 0ElseIf CLng(txtResult.Text & Chr(KeyAscii)) > 100 Or CLng(txtResult.Text & Chr(KeyAscii)) < 0 ThenKeyAscii = 0 End If(2)'限制文本框只能輸入數(shù)字和小數(shù)點(diǎn),但是不可以使用退格鍵If KeyAscii < 48 Or KeyAscii > 57 ThenIf KeyAscii = 46 ThenIf txtResult.Text = "" Or InStr(1, txtResult.Text, ".") <> 0 ThenKeyAscii = 0KeyAscii = 46End IfElseKeyAscii = 0End IfEnd If(3)既限制只輸入數(shù)字、小數(shù)點(diǎn)、又可以限制數(shù)值大小,也可以使用退格鍵 If KeyAscii <> Asc(".") And (KeyAscii <> 8) And (KeyAscii < Asc("0") Or KeyAscii > Asc("9")) ThenKeyAscii = 0ElseIf CLng(txtResult.Text & Chr(KeyAscii)) > 100 Or CLng(txtResult.Text & Chr(KeyAscii)) < 0 ThenKeyAscii = 0End If8.只能輸入文字,英文和空格:
Private Sub txtName_Change()txtName.MaxLength = 10 '限制長(zhǎng)度為10 End Sub Private Sub txtName_KeyPress(KeyAscii As Integer)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 ThenKeyAscii = 0End If End Sub9.限制只能輸入英文字母、數(shù)字以及退格:
Private Sub txtUserName_KeyPress(KeyAscii As Integer)Select Case KeyAsciiCase 48 To 57 '只能輸入數(shù)字Case 65 To 90 '只能輸入大寫(xiě)字母Case 97 To 122 '只能輸入小寫(xiě)字母Case 8 '只能輸入退格Case Else '否則KeyAscii = 0 '限制輸入,使輸入無(wú)效End Select End Sub'限制了用戶(hù)名只能輸入數(shù)字,大小寫(xiě)字母和刪除鍵,其他輸入均被視為無(wú)效輸入。10.限制特殊字符、數(shù)字、空格,只能輸入漢字和字母
Private Sub txtCoursename_KeyPress(KeyAscii As Integer)If KeyAscii < 0 Or KeyAscii = 8 Or KeyAscii = 13 ThenElseIf Not Chr(KeyAscii) Like "[a-zA-Z]" ThenKeyAscii = 0End If End Sub11.文本框限制特殊字符不可輸入:
Private SubtxtClassroom_KeyPress(KeyAscii As Integer)If ((KeyAscii >= 48 And KeyAscii <=57) Or (KeyAscii >= 65 And KeyAscii <= 90) Or _(KeyAscii >= 97 And KeyAscii <=122) Or (KeyAscii = 8)) = flase Then KeyAscii = 0 End Sub12.限制出生日期晚于入學(xué)日期:
Dim?borndate?As?Date?? Dim?getdate?As?Date'定義變量?? borndate?=Trim(txtBorndate.Text)?? getdate?=Trim(txtRudate.Text)?? If?getdate<=borndate?then'進(jìn)行比較??MsgBox"入學(xué)時(shí)間不能早于出生時(shí)間,請(qǐng)重新輸入",vbOKOnly?+?vbInformation,"警告"??txtRudate.SetFocus??Exit?Sub?? End?If??13.限制文本框輸入內(nèi)容的長(zhǎng)度
txtClassno.MaxLength = 1014.限制文本框輸入內(nèi)容的數(shù)值范圍
If Val(txtClassno.Text) > 2147483647 Or Val(txtClassno.Text) < 1ThenMsgBox "輸入數(shù)值在1到2147483647范圍內(nèi)"txtClassno.SetFocusExit Sub End If以上內(nèi)容是小編站在巨人的肩膀上學(xué)習(xí)和收獲到的,感謝走在前邊的大佬們,默默無(wú)言的給我提供了太多太多的幫助,讓我可以走的更加的穩(wěn)重,善于學(xué)習(xí)和應(yīng)用并且不斷總結(jié)和整理,把知識(shí)慢慢積累起來(lái),一點(diǎn)一點(diǎn)的成長(zhǎng)吧!
?
?
?
總結(jié)
以上是生活随笔為你收集整理的学生管理系统总结收获——限制字符的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: PS教程第八课:新建文件
- 下一篇: ucla ai_UCLA的可持续性:用户