VB代码片总结

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
评论 19
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值