lable控件可以作输入吗? 应该是text吧 if isnumeric(text1) then ..... .... else msgbox("输入错误“) endif
lable是不允许输入的 如果你是说Text控件,可以在keypress事件中实现 Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii < vbKey0 Or KeyAscii > vbKey9 Then KeyAscii = 0 MsgBox "Error!" End If End Sub
如果不包括小数点在内的话(因为小数点不是数字),还比较简单:dim Txt as stringTxt=trim(label1.text) if Len(Txt)=Len(Val(Txt) then 请试试!
抱歉,新版本,因为Label的文本属性为Caption 如果不包括小数点在内的话(因为小数点不是数字),还比较简单: dim Txt as string Txt=trim(label1.Caption) if Len(Txt)=Len(Val(Txt)) then 请试试! 解释:合法的样例:“123423”,“ 12340 " 非法的样例:“1334 54353",“432ab"," 1433 333333"," 341abb" 优点:可以集中一次性进行检测!避免单个字符的多次检测。
'label控件是不能输入内容的,改用textbox控件 if trim(text1.text)<>"" then if not isnumeric(text1.text) then msgbox "请输入数值型数据!",48,"提示" text1.setfocus exit sub else ..... end if else msgbox "请输入数据!",48,"提示" text1.setfocus end if
如果不包括小数点在内的话(因为小数点不是数字),还比较简单: dim Txt as string Txt=trim(Text1.Text) if Len(Txt)=Len(Val(Txt)) then 请试试! 解释:合法的样例:“123423”,“ 12340 " 非法的样例:“1334 54353",“432ab"," 1433 333333"," 341abb" 优点:可以集中一次性进行检测!避免单个字符的多次检测。
楼上的各位抱歉,我说错了,应该是textbox控件,不是LABLE控件
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
应该是text吧
if isnumeric(text1) then
.....
....
else
msgbox("输入错误“)
endif
如果你是说Text控件,可以在keypress事件中实现
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii < vbKey0 Or KeyAscii > vbKey9 Then
KeyAscii = 0
MsgBox "Error!"
End If
End Sub
if Len(Txt)=Len(Val(Txt) then
请试试!
如果不包括小数点在内的话(因为小数点不是数字),还比较简单:
dim Txt as string
Txt=trim(label1.Caption)
if Len(Txt)=Len(Val(Txt)) then
请试试!
解释:合法的样例:“123423”,“ 12340 "
非法的样例:“1334 54353",“432ab"," 1433 333333"," 341abb"
优点:可以集中一次性进行检测!避免单个字符的多次检测。
if trim(text1.text)<>"" then
if not isnumeric(text1.text) then
msgbox "请输入数值型数据!",48,"提示"
text1.setfocus
exit sub
else
.....
end if
else
msgbox "请输入数据!",48,"提示"
text1.setfocus
end if
MyVar = "459.95" ' 指定值。
MyCheck = IsNumeric(MyVar) ' 返回 True。
这里就出现了小数点了
dim Txt as string
Txt=trim(Text1.Text)
if Len(Txt)=Len(Val(Txt)) then
请试试!
解释:合法的样例:“123423”,“ 12340 "
非法的样例:“1334 54353",“432ab"," 1433 333333"," 341abb"
优点:可以集中一次性进行检测!避免单个字符的多次检测。
'-------------------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