加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

VB代码片总结

发布时间:2020-12-16 23:53:26 所属栏目:大数据 来源:网络整理
导读:1. 特殊符号的限制 (1)需设定是哪几个特殊符号 Dim a As String ,b As Long ,c As Long Dim i As Integer a = "'!@#$%^*()_+ " For i = 1 To 20 txtPassword. Text = Replace(txtPassword. Text , Mid (a,i, 1 ), "" ) Next (2)ASCII码限制输入符号 事件

1. 特殊符号的限制

(1)需设定是哪几个特殊符号

Dim a As String,b As Long,c As Long
Dim i As Integer
a = "'!@#$%^&*()_+ "
For i = 1 To 20
    txtPassword.Text = Replace(txtPassword.Text,Mid(a,i,1),"")
Next

(2)ASCII码限制输入符号

事件为:KeyPress

- 限制特殊字符

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

- 只允许输入数字

If KeyAscii = 8 Then Exit Sub     
    Select Case KeyAscii    
           Case 48 To 57       
           Case Else    
           KeyAscii = 0    
    End Select

- 只允许输入文本

If (KeyAscii < 0) Or (KeyAscii >= 65 And KeyAscii <= 90) Or(KeyAscii >= 97 And KeyAscii <= 122) Or (KeyAscii = 8) Then    
    Else    
          MsgBox "请输入字母或汉字",vbOKOnly,"提示"    
          KeyAscii = 0    
    End If

特殊符号的限制方法还有很多种

2. 窗体美观优化

使窗体不能随便更改大小:BorderStyle改为1-FixedSingle
窗体居中显示:

With Me
          .BorderStyle = 0
          .Left = FrmMain.ScaleWidth / 2 - .Width / 2
          .Top = FrmMain.ScaleHeight / 2 - .Height / 2
  End With

3. 密码输入3次错误,设提示

miCount = miCount + 1
  If miCount > 3 Then
           MsgBox "你已经超过允许验证次数!",vbOKOnly + vbExclamation,"提示"
           Me.Hide
           Exit Sub
  End If

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读