中易网

VB:输入半径,计算圆周长和圆面积。运行界面如下

答案:2  悬赏:40  
解决时间 2021-01-13 13:56
  • 提问者网友:欺烟
  • 2021-01-13 03:17
VB:输入半径,计算圆周长和圆面积。运行界面如下
最佳答案
  • 二级知识专家网友:从此江山别
  • 2021-01-13 03:47
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
全部回答
  • 1楼网友:鱼芗
  • 2021-01-13 04:19
不了解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
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息