学生系统优化——字符限定
生活随笔
收集整理的這篇文章主要介紹了
学生系统优化——字符限定
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
一、文本框限定
1、限定輸入的字符長度
文本框中有個MaxLength屬性,輸入自己要限定的數(shù)字即可;也可以利用代碼來限定,當(dāng)超過限定長度時,彈出警告對話窗
Private sub txtUserName_change()If Len(Trim(txtUserName)) > 4?thenMsgBox "姓名不能超過4個字符,請重新輸入!", 0 + 48txtUserName = ""End if? End iSubTrim函數(shù)是消除字符串的空格,Len函數(shù)是計(jì)算字符串的長度
2、限定特殊字符
Private Sub txtUserName_Change()If Len(Trim(txtUserName)) > 4 thenMsgBox "姓名不能超過4個字符,請重新輸入!", 0 + 48txtUserName = ""End if End sub3、限定輸入的字符類型
Private Sub txtSID_KeyPress(KeyAscii As Integer)Const xStr As String = "123456" '只能輸入數(shù)字KeyAscii = IIf(Instr(xStr & Chr(8), Chr(KeyAscii)), KeyAscii, 0) End Sub4、限定特殊字符
Private Sub txtDirector_KeyPress(KeyAscii As Integer)Select Case KeyAsciiCase 8 '限制退格鍵Case Asc("A") To ("Z")Case Asc("a") To ("z")Case Is < 0Case ElseKeyAscii = 0MsgBox "格式錯誤,請輸入漢字或英文!", 0 + 48txtDirector.Text = ""End Select End Sub5、只能輸入數(shù)字
If keyAscii = 8 Then Exit Sub If keyAscii < 48 Or keyAscii > 57 Then keyAscii = 06、限制數(shù)字大小,這個適合成績對話框
Private Sub txtResult_change() On Error Resume Next If Val(Trim(txtResult.Text)) > 100 Then MsgBox "輸入數(shù)字過大,請重新輸入" txtResult.Text = "" End If End Sub?7、不能輸入特殊字符(和第二、四個一樣的性質(zhì))
Select Case keyAscii Case -20319 To -3652 Case 48 To 57 Case 65 To 98 Case 97 To 122 Case 8 Case Else keyAscii = 0 End Select?8、限定特殊字符、數(shù)字、空格,只能輸入漢字和字母
Private Sub txtCourseName_KeyPress(KeyAscii As Integer)If KeyAscii < 0 or KeyAscii = 8 or KeyAscii = 13 ThenElse IfNot chr(KeyAscii) Like "[a-ZA-Z]" ThenkeyAscii = 0End if End sub二、下拉框限定?
Combox限定不能鍵盤輸入,只能選擇下拉框里面的內(nèi)容
Private Sub comboGrade_KeyPress(KeyAscii As Integer)KeyAscii = 0 '限制鍵盤不能輸入內(nèi)容 End Sub三、限定成績
Private Sub txtResult_Change()If Val(txtResult.Text) > 120 Or Val(txtResult.Text) < 0 ThenMsgBox "請輸入成績在0~120范圍內(nèi)!", 0 + 48txtResult.Text = ""End If End Sub四、限定不能復(fù)制粘貼
在第二次輸入密碼時,不能復(fù)制粘貼
Private Sub txtPassword1_KeyDown(KeyCide As Integer, Shift As Integer)If (KeyCode = 86 Or KeyCode = 67 Or KeyCode = 88) And Shift = 2 ThenMsgBox "不能復(fù)制粘貼", 0 + 48txtPassword1.Text = ""End If End Sub提示密碼剩余次數(shù)
If miCout = 1 ThenMsgBox "您還有兩次機(jī)會", 0 + 48,"提示" Exit sub End IfIf miCout = 2 ThenMsgBox "您還有一次機(jī)會", 0 + 48,"提示" Exit sub End IfIf miCout = 3 ThenMsgBox "即將關(guān)閉程序", 0 + 48,"提示"Me.Hide Exit sub End If?
?
?
?
??
總結(jié)
以上是生活随笔為你收集整理的学生系统优化——字符限定的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: figma下载_Figma中的高级图像处
- 下一篇: 指针和指针的指针_网络上的iPad指针