请问,如何能限制文本框,让其只能输入数字,谢谢。

解决方案 »

  1.   

    文本框的KeyPress事件:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
     If (KeyAscii < 48 Or KeyAscii > 57) Then
      KeyAscii = 0
     End If
    End Sub
      

  2.   

    Private Sub Command1_Click()
    If IsNumeric(Text1.Text) Then
    MsgBox "数字"
    Else
    MsgBox "字母"
    End IfEnd Sub
      

  3.   

    Text1只能输入数字
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    Dim Numbers As String
    Numbers = "1234567890" + Chr(8) + Chr(46)
    If InStr(Numbers, Chr(KeyAscii)) = 0 Then
        KeyAscii = 0
    End If
    End Sub
      

  4.   

    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If isnumeric(chr(keyascii))=false Then
        KeyAscii = 0
    End If
    End Sub
      

  5.   

    根本不用,textbox有一个属性,可以指定只能输入数字.
      

  6.   

    to  cngxylyh(olo):有这样一个属性吗??你是不是在想 maskedit 呢?
      

  7.   

    if isnumeric(text1.text) then
      你要实现的条件
    else
      ___
      

  8.   

    FDSS(旷野黎明·甜笑) 的方法不好,不能退格。既然要限制,就完美一些。 cuilei197979(风) 的不错
      

  9.   

    其实还有一些输入控件比如说true dbinput,直接用属性控制,很好用的,对字符串类型、长度、格式等都有相应属性,省去些校验代码了。方便
      

  10.   

    在定义的模块中加入以下定义,才可以用GetAsyncKeyState
    Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer