添加一个类模块.名为Class1
代码:
Option Explicit
Public Function isDigst(str As String) As Boolean
If IsNumeric(str) Then
isDigst = True
Else
isDigst = False
End If
End Function
回到Form1,添加一个CommandButton
代码:
Option Explicit
Dim clsDig As New Class1
Private Sub Command1_Click()
Dim s As String
Dim b As Boolean
s = "1253"
b = clsDig.isDigst(s)
If b Then
MsgBox s & "数字"
Else
MsgBox s & "非数字"
End If
s = "a12"
b = clsDig.isDigst(s)
If b Then
MsgBox s & "数字"
Else
MsgBox s & "非数字"
End If
End Sub