如题要求只允许被输入正整数,空格 小数点 负号 字母等等都不要,就要正整数谢谢

解决方案 »

  1.   

    private sub text1_lostfocus()
        if text1.text<>"" then
            if not isnumeric(text1.text) then
                msgbox "请输入数值型数据!",48,"提示"
                text1.setfocus
            else
                '取整,取绝对值
                text1.text=abs(int(text1.text))
            end if
        end if
    end sub
      

  2.   

    Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
        If Index = 1 Then
            If Not ((KeyAscii >= 48 And KeyAscii <= 57) Or (KeyAscii = 8)) Then
                KeyAscii = 0
            End If
        End If
    End Sub