VB限制代码

内联代码片

限制教室文本框只能输入汉字和数字
    If ((KeyAscii <= 57 And KeyAscii >= 48) Or (KeyAscii <= -3652 And KeyAscii >= -20319) Or KeyAscii = 8) = False Then KeyAscii = 0
    txtClassroom.MaxLength = 15
End Sub

限制特殊字符、数字、空格,只能输入汉字和字母

Select Case KeyAscii
Case -20319 To -3652
Case 48 To 57
Case 65 To 90
Case 97 To 122
Case 8
Case Else
KeyAscii = 0
End Select    

不能输入特殊字符`。

If KeyAscii < 0 Or KeyAscii = 8 Or KeyAscii = 13 Then
        ElseIf Not Chr(KeyAscii) Like "[a-zA-Z]" Then
    KeyAscii = 0
    MsgBox "请输入汉字或字母", vbOKOnly + vbExclamation, "提示"
    txtDirector.MaxLength = 20
End If

禁止复制粘贴

If Shift = 2 Then
            MsgBox "不准复制粘贴", vbOKOnly + vbExclamation, "提示"
        End If

限制只能数字和退格键

Select Case KeyAscii
Case 48 To 57
Case 8
Case Else
KeyAscii = 0
MsgBox “请输入数字”, vbOKOnly + vbExclamation, “提示”
txtClassno.Text = “”

只能输入汉字

If KeyAscii >= -20319 And KeyAscii <= -3652 Or KeyAscii = 8 Then
Else
KeyAscii = 0
MsgBox “请输入汉字!”, vbOKOnly + vbExclamation, “提示”
txtCoursedes.SetFocus
txtCoursedes.MaxLength = 20
End If

下面展示一些 `内联代码片`。

If Len(txtCoursename) > 10 Then
KeyAscii = 0
MsgBox “字数超出”, vbOKOnly + vbExclamation, “提示”
End If

下面展示一些 `内联代码片`。

Dim borndate As Date
Dim getdate As Date '定义变量
'borndate = Trim(dtpborn.Text)
'getdate = Trim(dtpborn.Text)
If getdate <= borndate Then '进行比较
MsgBox “入学时间不能早于出生时间,请重新输入”, vbOKOnly + vbInformation, “警告”
dtpborn.SetFocus
Exit Sub


评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值