Private Sub Text1_Validate(Cancel As Boolean) if not IsNumric(Text1.text) then Cancel=true msgbox "error!" end if End Sub
Private Sub Text1_LostFocus()If Not IsNumeric(Text1.Text) Then MsgBox "error" End If End Sub
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 这个是控制判断输入好的数据是不是数字
Private Sub Text1_LostFocus() If Not IsNumeric(Text1.Text) Then MsgBox "error" End If End Sub
Private Sub Text1_LostFocus() if text1.text<>"" then If Not IsNumeric(Text1.Text) Then MsgBox "error" end if End If End Sub
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
if not IsNumric(Text1.text) then
Cancel=true
msgbox "error!"
end if
End Sub
MsgBox "error"
End If
End Sub
一:
'********************************************************
'
' 过程名称 : 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
这个是控制判断输入好的数据是不是数字
If Not IsNumeric(Text1.Text) Then
MsgBox "error"
End If
End Sub
if text1.text<>"" then
If Not IsNumeric(Text1.Text) Then
MsgBox "error"
end if
End If
End Sub
'-------------------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