请问如何判断textbox控件接受的字符串全部是数字

zjlsct 2003-06-20 03:02:48
或者如何让textbox只能输入数字
...全文
37 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
饮水需思源 2003-06-20
  • 打赏
  • 举报
回复
private sub text1_lostfocus()
if trim(text1.text)<>"" then
if not isnumeric(text1.text) then
msgbox "请输入数值型数据!",48,"提示"
text1.setfocus
end if
end if
end sub
DaiLM 2003-06-20
  • 打赏
  • 举报
回复
If Len(Trim(txtNum.Text)) = Len(CStr(Val(txtNum.Text))) Then
MsgBox "True"
Else
MsgBox "False"
End If
zjlsct 2003-06-20
  • 打赏
  • 举报
回复
是啥?函数?好像没这个函数吧
freeda 2003-06-20
  • 打赏
  • 举报
回复
楼上的IsNumberic(TextBox.text)会碰到很多问题,万一用户输入了字符呢?
bydisplay 2003-06-20
  • 打赏
  • 举报
回复
Private Sub Text1_Change()
If Not ValidateNumeric(Text1.Text) Then

Text1.Text = ""

End If


End Sub
Private Function ValidateNumeric(strText As String) As Boolean

ValidateNumeric = CBool(IsNumeric(strText))

End Function

freeda 2003-06-20
  • 打赏
  • 举报
回复
在keypress事件的时候限定KeyAscii的值在asc("0")~asc("9")之间
同时注意[TAB]和[Backspace]最好也允许输入,还有"."
例如
Private Sub txtTotal_KeyPress(KeyAscii As Integer)
KeyAscii = ValidateData_Number(KeyAscii)
End Sub


这是我写的函数,平时用的,作为参考
Public Function ValidateData_Number(ByVal vData As Integer) As Integer
'{0-9,'+','-','.'} Supported
'BACKSPACE,DELETE Supported
'Return: KeyAscii As Integer
' 0:Invalidate Key Press

If (vData > 47) And (vData < 58) Then
ValidateData_Number = vData
ElseIf (vData = 46) Or (vData = 45) Or (vData = 43) Or (vData = 8) Or (vData = 13) Then
ValidateData_Number = vData
Else
ValidateData_Number = 0
End If

End Function
Alicky 2003-06-20
  • 打赏
  • 举报
回复
if IsNumberic(TextBox.text) then
'数字类型
else
'非数字类型
endif
gxingmin 2003-06-20
  • 打赏
  • 举报
回复
if isnumeric(textbox.text) then
msgbox "数字"
else
msgbox "不全是"
end if
flxa 2003-06-20
  • 打赏
  • 举报
回复
用isnum....()

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧