Private Function Is123(ByVal MyStr As String) As Boolean Dim intLoop As Integer Is123 = False For intLoop = 1 To Len(MyStr) If Not (Mid(MyStr, intLoop, 1) Like "#") Then Exit Function End If Next intLoop Is123 = True End FunctionPrivate Sub Command1_Click() Debug.Print Is123("456") Debug.Print Is123("234.6") End Sub
Private Sub Command3_Click() a = Text1.Text b = CStr(Val(Text1.Text)) If a = b Then MsgBox "全数字" End Sub
MyStr = "ABC1234"
MsgBox IsNumeric(MyStr) 'False
MyStr = "1234"
MsgBox IsNumeric(MyStr) 'True
MyStr = "12.34"
MsgBox IsNumeric(MyStr) 'True
而楼主要求为FALSE,因为当中有个非数字的小数点.楼主的问题有趣,但似乎只能通过自定义函数解决.
真的没别的函数了吗?
Dim intLoop As Integer
Is123 = False
For intLoop = 1 To Len(MyStr)
If Not (Mid(MyStr, intLoop, 1) Like "#") Then
Exit Function
End If
Next intLoop
Is123 = True
End FunctionPrivate Sub Command1_Click()
Debug.Print Is123("456")
Debug.Print Is123("234.6")
End Sub
a = Text1.Text
b = CStr(Val(Text1.Text))
If a = b Then MsgBox "全数字"
End Sub