只输入数字已经搞定.可是不知道怎样才能限定user只输入9个数字呢?
谢啦~

解决方案 »

  1.   

    在KeyPress事件中判断Len(text1.text)是否>=9,如果这样使输入无效(KeyAscii = 0)
      

  2.   

    在datachange事件中,
    当输入一个字符时就判断其ASCII的范围!!
      

  3.   

    来自lxcc(虫子|需要点勇气和信心) 的帖子
    不用写控件,可以用一个如下的代码:Private Sub Text1_KeyPress(KeyAscii As Integer)
        InputNumeric KeyAscii, Text1
    End Sub'*****************************************************************
    '文本框只能输入数字Public Sub InputNumeric(KeyAscii As Integer, txtItem As TextBox)
        Select Case KeyAscii
            Case Asc("-") '允许负数
                If txtItem.SelStart = 0 Then
                  If Left(txtItem.Text, 1) = "-" Then
                      KeyAscii = 0
                      Beep
                  End If
                Else
                  KeyAscii = 0
                  Beep
                End If
            Case 8
                  '无变化,退格键不屏蔽
            Case Asc(" ") '32
                If txtItem.SelLength = 0 Then
                    KeyAscii = 0
                End If
            Case Asc(".") '46 '允许小数点
                If InStr(txtItem.Text, ".") Then
                    KeyAscii = 0
                End If
            Case Is < Asc(0) '48
                  KeyAscii = 0
            Case Is > Asc(9) '57
                  KeyAscii = 0
        End Select
    End Sub
    '*****************************************************************