1)只能输入“数字”和“:”    //用于输入时间
2)只能输入“<”,“>”,“=”   //用于比较
3)只能输入大写字母

解决方案 »

  1.   

    1、
    Private Sub Text1_KeyPress(KeyAscii As Integer)
       If KeyAscii > 58 Or KeyAscii < 48 Then  '58为:的ascii值
          Exit Sub
       End If
    End Sub2、
    Private Sub Text1_KeyPress(KeyAscii As Integer)
       If KeyAscii <> 60 Or KeyAscii <> 61 Or KeyAscii <> 62 Then
          Exit Sub
       End If
    End Sub
    3、
    Private Sub Text1_KeyPress(KeyAscii As Integer)
       If KeyAscii > 65 Or KeyAscii < 90 Then
          Exit Sub
       End If
    End Sub
      

  2.   

    用掩码控件,在工程-部件-下添加microsoft masked ecit control 6.0 再添加相应的代码即可
      

  3.   

    Private Sub Text1_KeyPress(KeyAscii As Integer)
     Dim t As Integer
     Print KeyAscii
     If KeyAscii >= 65 And KeyAscii <= 90 Then t = 1 'A-Z
     If KeyAscii >= 48 And KeyAscii <= 57 Then t = 1 '0-9
     If KeyAscii >= 60 And KeyAscii <= 62 Then t = 1 '<>=
     If t <> 1 Then KeyAscii = 0
    End Sub
      

  4.   

    '文本框中只可以输入数字
    Private Sub txtidentitycode_KeyPress(KeyAscii As Integer)
      If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then KeyAscii = 0
    End Sub'只能输入“<”,“>”,“=”用于比较
    Private Sub txtidentitycode_KeyPress(KeyAscii As Integer)
      If KeyAscii <> 60 And KeyAscii <> 61 And KeyAscii <> 62 Then KeyAscii = 0
    End Sub'只能输入大写字母
    Private Sub txtidentitycode_KeyPress(KeyAscii As Integer)
      If KeyAscii < 65 Or KeyAscii > 90 Then KeyAscii = 0
    End Sub
      

  5.   

    Private Sub Text1_KeyPress(KeyAscii As Integer)
     Dim t As Integer
     If KeyAscii = 58 Then t = 1 ':
     If KeyAscii >= 65 And KeyAscii <= 90 Then t = 1 'A-Z
     If KeyAscii >= 48 And KeyAscii <= 57 Then t = 1 '0-9
     If KeyAscii >= 60 And KeyAscii <= 62 Then t = 1 '<>=
     If t <> 1 Then KeyAscii = 0
    End Sub
    忘了写冒号了,补上,以上你要输入什么就加什么if语句就成了
      

  6.   

    写一个比较过程,当TEXTBOX变化时对比判断,程序如下~~~
    Dim mytext As StringPrivate Sub Form_Load()
      mytext = "0123456789~!@#$%^&*()_+|\=-][';/.,<>?:"{}"  '这里存的是允许输入的字符~
    End Sub
    Private Sub Text1_KeyPress(KeyAscii As Integer)
      KeyAscii = TestText(KeyAscii, Mytext, True) 'Text1只接受mytext规定的字符。
    End Sub
    Function TestText(KeyIn As Integer, ListString As String, EditBasp As Boolean) As Integer
      Dim TestDATList As String '定义限制字符表变量
      Dim KeyOut As Integer '返回值变量
      If EditBasp = True Then '测试BACKSPACE键是否有效
        TestDATList = UCase(ListString) & Chr(8) '得到含BACKSPACE键字符的大写表
      Else
        TestDATList = UCase(ListString) '得到无BACKSPACE键字符的大写表
      End If
      If InStr(1, TestDATList, UCase(Chr(KeyIn)), 1) > 0 Then '键值是否在表中
        KeyOut = KeyIn '是则附键值
      Else
        KeyOut = 0 '否则键值无效
      End If
      TestText = KeyOut '返回结果
    End Function另外改一下就可以是这个程序接受规定字符以外的字符
    http://expert.csdn.net/Expert/topic/1768/1768883.xml?temp=.5056726和这个差不多,就是改了一点~~可以去看看~~