关于textbox的问题,如何让用户只能输入小于某一整数的办法

解决方案 »

  1.   

    在textbox的keydown 或 keypress事件中,编写以下代码,试一试
    if clng(text1.text)>=500 then
      text1.text=""
      msgbox"请输入小于500的数!"
    end if
    因为没vb,没法试,你自己试一试吧!
      

  2.   

    Private Sub Text1_LostFocus()
    If IsNumeric(Text1.Text) = True Then
    If CLng(Text1.Text) >= 500 Then
      Text1.Text = ""
      MsgBox "请输入小于500的数!"
    End If
    Else
    MsgBox "不是数字"
    End If
    End Sub
    试试
      

  3.   

    输入的数据触发事件,判断text.text的内容是否合法,如果不合法清空text,得到焦点。
      

  4.   

    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If Chr(KeyAscii) > 3 Then
      MsgBox "sorry"
    End IfEnd Sub
      

  5.   

    Private Sub Text1_Validate(Cancel As Boolean)
        If Val(Text1.Text) > 500 Then
            Cancel = True
            Text1.SelStart = 0
            Text1.SelLength = Len(Text1.Text)
        End If
    End Sub
      

  6.   

    itcoco(无忧草) 想得很好很严密,正是我要提出的地方。
      

  7.   

    to gongyueqintina(绿色绿珠) 
    我试过行啊,你是不是用的是小键盘?
      

  8.   

    Private Sub Text1_Change()
    If Text1.Text <> "" Then
        If Val(Mid(Text1.Text, Len(Text1.Text), 1)) > 3 Then
            MsgBox "sorry"
        End If
    End If
    End Sub
      

  9.   

    Private Sub Text1_KeyPress(KeyAscii As Integer)Dim Numbers As StringNumbers = "1234567890" + Chr(8) + Chr(46)    ' Chr(8) 空格 + Chr(46) 小数点If KeyAscii = 13 Then    ' 如果键入回车键则进行下一步动作    If Val(Text1.Text) < 500 Then
        
            '省略...
            
        Else
        
            MsgBox "请输入小于500的数!"    End If
        
    ElseIf InStr(Numbers, Chr(KeyAscii)) = 0 Then    ' 确保只能输入数字    KeyAscii = 0
        
    End IfEnd Sub