日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

学生管理系统总结收获——限制字符

發布時間:2023/12/9 windows 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 学生管理系统总结收获——限制字符 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一.ASCII碼——限制字符問題

在敲學生的時候需要設置很多限制條件,比如限制字符,顯示數據類型,限制字符長度等等,其中有很多限制需要通過ASCII碼來進行代碼編寫限制,數不勝數,小編至今還是有很多限制條件的ASCII 不知道,記是永遠記不住的,未來用到的時候再多多補充啦。下面是小編在優化學生時經常用到的一些代碼限制條件,分享給大家。

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 Sub

2.只能輸入文字及刪除鍵:

Private Sub Text1_KeyPress(KeyAscii As Integer)If KeyAscii >= -20319 And KeyAscii <= -3652 Or KeyAscii = 8 ThenElseKeyAscii = 0End If End Sub

3.限制只能輸入數字:

If KeyAscii = 8 Then Exit Sub If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0

4.限制只能輸入數字和刪除鍵:

If KeyAscii <> 8 And (KeyAscii < 48 Or KeyAscii > 57) ThenKeyAscii = 0End if

5.只能輸入數字和文字:

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

6.只能輸入數字和英文字母:

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 Sub

7.只輸入數字、小數和刪除鍵:

If KeyAscii <> Asc(".") And (KeyAscii <> 8) And (KeyAscii < Asc("0") Or KeyAscii > Asc("9")) ThenKeyAscii = 0End If'添加成績窗體限制成績: (1)限制添加成績窗體只能輸入數字且大于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)'限制文本框只能輸入數字和小數點,但是不可以使用退格鍵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)既限制只輸入數字、小數點、又可以限制數值大小,也可以使用退格鍵 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 If

8.只能輸入文字,英文和空格:

Private Sub txtName_Change()txtName.MaxLength = 10 '限制長度為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 Sub

9.限制只能輸入英文字母、數字以及退格:

Private Sub txtUserName_KeyPress(KeyAscii As Integer)Select Case KeyAsciiCase 48 To 57 '只能輸入數字Case 65 To 90 '只能輸入大寫字母Case 97 To 122 '只能輸入小寫字母Case 8 '只能輸入退格Case Else '否則KeyAscii = 0 '限制輸入,使輸入無效End Select End Sub'限制了用戶名只能輸入數字,大小寫字母和刪除鍵,其他輸入均被視為無效輸入。

10.限制特殊字符、數字、空格,只能輸入漢字和字母

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 Sub

11.文本框限制特殊字符不可輸入:

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 Sub

12.限制出生日期晚于入學日期:

Dim?borndate?As?Date?? Dim?getdate?As?Date'定義變量?? borndate?=Trim(txtBorndate.Text)?? getdate?=Trim(txtRudate.Text)?? If?getdate<=borndate?then'進行比較??MsgBox"入學時間不能早于出生時間,請重新輸入",vbOKOnly?+?vbInformation,"警告"??txtRudate.SetFocus??Exit?Sub?? End?If??

13.限制文本框輸入內容的長度

txtClassno.MaxLength = 10

14.限制文本框輸入內容的數值范圍

If Val(txtClassno.Text) > 2147483647 Or Val(txtClassno.Text) < 1ThenMsgBox "輸入數值在1到2147483647范圍內"txtClassno.SetFocusExit Sub End If

以上內容是小編站在巨人的肩膀上學習和收獲到的,感謝走在前邊的大佬們,默默無言的給我提供了太多太多的幫助,讓我可以走的更加的穩重,善于學習和應用并且不斷總結和整理,把知識慢慢積累起來,一點一點的成長吧!

?

?

?

總結

以上是生活随笔為你收集整理的学生管理系统总结收获——限制字符的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。