在VB中怎样判断文本框数组是否输入的是数字

文本框数组1 to 8的 怎么样实现 文本框是否输入的是数字而不是其他

何不让文本框只接受数字呢?这样不是更合理一点。实现方法如下: Public Function ImportNum(KeyIn As Integer, ValidateString As String, Editable As Boolean) As Integer
Dim ValidateList As String
Dim KeyOut As Integer
If Editable = True Then
ValidateList = UCase(ValidateString) & Chr(8)
Else
ValidateList = UCase(ValidateString)
End If
If InStr(1, ValidateList, UCase(Chr(KeyIn)), 1) > 0 Then
KeyOut = KeyIn
Else
KeyOut = 0
Beep
End If
ImportNum = KeyOut
End Function '函数ImportNum使用方法Private Sub Text1_KeyPress(KeyAscii As Integer)
KeyAscii = ImportNum(KeyAscii, "0123456789" & Chr(13), True) 'Chr(13)代表回车
End Sub 使用该函数使得TEXTBOX只能输入你指定的值。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-12-19
用KeyPress可以轻松检验,0-9对应的ASCII值为48-57,用如下代码可以作测试Private Sub Text1_KeyPress(KeyAscii As Integer)
if KeyAscii>=48 and KeyAscii<=57 then msgbox "输入的是数字" end ifEnd Sub
第2个回答  2013-12-19
用:isnumeric这个函数判断!
第3个回答  2013-12-19
使用IsNumber函数
相似回答