我有两个txtbox是写数字的,VB中的 txtbox怎么样才可以只接收数字呢!

解决方案 »

  1.   

    IsNumeric("002")=true   '是数字
      

  2.   

      在KeyPress事件中处理:
    Private Sub txtInput_KeyPress(KeyAscii As Integer)
        If (KeyAscii < 0) Then KeyAscii = 0: Exit Sub
        If (KeyAscii < 32) Then Exit Sub
        If ((KeyAscii < 48) OR (KeyAscii > 57) Then  KeyAscii = 0End Sub  这样就只能输入数字了。
      

  3.   

    KeyPress里判断一下Ascii就可以了
      

  4.   

    If (KeyAscii<vbKey0 or KeyAscii>vbKey9) then
        KeyAscii=vbCancel
    endif
      

  5.   

    判断ASCII值,3楼、5楼的就是!
      

  6.   

    Public Function Digit_Only(byval keyascii As integer) As Integer
        Select Case keyascii
            Case 8, 9, 13, &H2E, &H30 To &H39  '允许Tab, Back Space, Enter, 小数点和数字键
                Digit_Only = keyascii
            Case Else
                Digit_Only = 0
        End Select
    End FunctionPrivate Sub Text1_KeyPress(KeyAscii As Integer)
        KeyAscii = Digit_Only(KeyAscii)
    End SubPrivate Sub Text2_KeyPress(KeyAscii As Integer)
        KeyAscii = Digit_Only(KeyAscii)
    End Sub