第1个回答 2012-11-24
不了解isnumeric,写了个函数
Private Sub Command1_Click()
Dim r As Single
If isval(Trim(Text1.Text)) Then
r = Val(Text1.Text)
Text2.Text = 3.14 * r * r
Else
MsgBox "input error"
Text1.SetFocus
End If
End Sub
Private Sub Command2_Click()
Dim r As Single
If isval(Trim(Text1.Text)) Then
r = Val(Text1.Text)
Text3.Text = 2 * 3.14 * r
Else
MsgBox "input error"
Text1.SetFocus
End If
End Sub
Function isval(str As String) As Boolean
Dim strCmp
Dim i As Integer
Dim strTemp As String
strCmp = "0123456789."
isval = True
For i = 1 To Len(str)
strTemp = Mid(str, i, 1)
If Mid(str, i, 1) = "." And Mid(str, i + 1, 1) = "" Then
isval = False
Exit Function
End If
If InStr(strCmp, strTemp) = 0 Then
isval = False
Exit Function
End If
Next
Dim str1() As String
str1 = Split(str)
If UBound(str1) > 0 Then
isval = False
Exit Function
End If
End Function
第2个回答 推荐于2017-09-16
Private Sub Command1_Click()
If Not IsNumeric(Text1) Then
MsgBox "xxx"
Text1.SetFocus
Exit Sub
End If
Dim r As Single
r = Val(Text1.Text)
Text2.Text = 3.14 * r * r
End Sub
Private Sub Command2_Click()
If Not IsNumeric(Text2) Then
MsgBox "xxx"
Text2.SetFocus
Exit Sub
End If
Dim r As Single
r = Val(Text1.Text)
Text3.Text = 2 * 3.14 * r
End Sub本回答被提问者和网友采纳