用text,不使用maskEditBox,焦点移出时,判断text输入的是否数字,若不是,msgbox "error!"

解决方案 »

  1.   

    Private Sub Text1_Validate(Cancel As Boolean)
    if not IsNumric(Text1.text) then
    Cancel=true
    msgbox "error!"
    end if
    End Sub
      

  2.   

    Private Sub Text1_LostFocus()If Not IsNumeric(Text1.Text) Then
      MsgBox "error"
    End If
    End Sub
      

  3.   

    2个方法:
    一:
    '********************************************************
    '
    '  过程名称 : txt20price_KeyPress
    '
    '  功能说明 : 回车响应,控制输入
    '
    '*******************************************************
    Private Sub txt20price_KeyPress(KeyAscii As Integer)
        If (KeyAscii > 57 Or KeyAscii < 48) And KeyAscii <> 46 And KeyAscii <> 13 And KeyAscii <> 8 Then
           SendKeys "{bs}"
           txt20Price.SetFocus
           Exit Sub
        End If
    End Sub
    这个是控制输入,不是数字就不能输入二:Dim mayvar As Boolean
        mayvar = IsNumeric(Trim$(txt20Price.Text))
        If mayvar = False Then
          MsgShow "请输入正确的价格"
           txt20Price.Text = ""
           txt20Price.SetFocus
           Exit Sub
        End If
    这个是控制判断输入好的数据是不是数字
      

  4.   

    Private Sub Text1_LostFocus()
      If Not IsNumeric(Text1.Text) Then
         MsgBox "error"
      End If
    End Sub
      

  5.   

    Private Sub Text1_LostFocus()
        if text1.text<>"" then  
            If Not IsNumeric(Text1.Text) Then
                MsgBox "error"
            end if 
        End If
    End Sub
      

  6.   

    Public Function sffunLimitNumber(ByVal IntVal As Integer) As Integer
    '-------------------1-------------------
    '目    的:只允许在文本框内输入数字、退格、删除及回车键
    '输    入:ByVal IntVal As Integer,任意的键值
    '被传递值:无
    '返 回 值:过滤后的键值
    '输    出:无
    '注    解:
    '用    法:在文本框的KeyPress事件中输入KeyAscii = sffunLimitNumber(KeyAscii)即可
    '修 订 版:
    '-------------------1-------------------
    If (IntVal <> vbKeyDelete) _
    And (IntVal <> vbKeyBack) _
    And (IntVal <> 13) _
    And (IntVal < 48 Or IntVal > 57) Then
        IntVal = 0
    End If
    sffunLimitNumber = IntValEnd Function