这个问题有点复杂,实时的限制一个文本框text的输入内容,一旦错误就弹出提示框?
1.要求
①只能输入数字,等号
②界面只接收数字,等号,回车和删除键2.实现效果:
当一个文本框内输入合法字符的时候,不提示
当一个文本框内输入非法的时候,输完就立刻弹出msgbox提示有多余字符输入3.示例:
正确例子:
123=01
23456=12错误的例子:
123=01
23456=12234=0已经实现的部分代码只接收数字,等号,回车和删除键的代码
Private Sub Text1_KeyPress(KeyAscii As Integer)If KeyAscii = 8 Or KeyAscii = 13 Or KeyAscii = 61 Then Exit Sub '删除键、回车键例外
If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0End Sub如何实现,输入立即自动提示,现在要解决的问题就是多余回车,只要输入多余回车就报错??
是否需要用到正则表达式?

解决方案 »

  1.   

    我怎么没看懂这错误例子和正确例子有什么区别?
    剩下你要干的,就是排除多个回车的情况?ubound(split(text1.text,chr(13)))>1应该可以判断吧
      

  2.   

    看看我的这篇博客,可能对你有帮助。
    http://blog.csdn.net/supermanking/article/details/2959044
      

  3.   


    其实不需要弹出对话框,禁止输入就可以了:(Text1 设置 MultiLine 属性 = True)Option Explicit
    Dim blnLastEqual As BooleanPrivate Sub Text1_Change()
    Dim myStart As Long
        myStart = Text1.SelStart
        Text1.Text = Replace(Text1.Text, vbCrLf & vbCrLf, vbCrLf)
        If myStart > Len(Text1.Text) Then
            Text1.SelStart = Len(Text1.Text)
        Else
            Text1.SelStart = myStart
        End If
    End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
        Case 8, Asc("0") To Asc("9")
            blnLastEqual = False
        Case Asc("=")
            If Mid(Text1.Text, Text1.SelStart, 1) = "=" Then
                KeyAscii = 0
            Else
                blnLastEqual = False
            End If
        Case 13
            If blnLastEqual Then
                KeyAscii = 0
            Else
                blnLastEqual = True
            End If
        Case Else
            KeyAscii = 0
    End Select
    End Sub