...计算圆面积和圆周长。计算结果数据类型为单精度型。
发布网友
发布时间:2024-09-30 10:24
我来回答
共2个回答
热心网友
时间:2024-09-30 13:15
①方法1:
Private Sub Command1_Click()
Dim p As Single
Dim s As Single
Dim r As Single
p = 3.1415 '定义PAI的值
r = Val(Text1)
s = p * r ^ 2 '面积公式
c = 2 * p * r '周长公式
Label2.Caption = c '标签2输出周长结果
Text2 = s '文本框2输出面积结果
End Sub
②方法2
Private Sub Command1_Click()
Dim p As Single
Dim s As Single
Dim r As Single
p = 3.1415 '定义PAI的值
r = InputBox("请输入一个圆的半径", "输入", 0) '获取输入值
s = p * r ^ 2 '面积公式
c = 2 * p * r '周长公式
MsgBox ("圆的面积为:" & s & "圆的周长为:" & c) '输出结果
End Sub
热心网友
时间:2024-09-30 13:20
①方法1:
Private Sub Command1_Click()
Dim p As Single
Dim s As Single
Dim r As Single
p = 3.1415 '定义周长率的值
If Text1.Text = "" Then'判断是否输入半径
MsgBox "请输入圆的半径!"
Text1.SetFocus
Exit Sub
End If
If Not IsNumeric(Text1.Text) Then'判断是否输入数字
MsgBox "请输入数字"
Text1.SetFocus
Exit Sub
End If
r = Val(Text1.Text)
s = p * r ^ 2 '面积公式
c = 2 * p * r '周长公式
Text2 = s '文本框2输出面积结果
Label2.Caption = c '标签2输出周长结果
End Sub
②方法2
Private Sub Command1_Click()
Dim p As Single
Dim s As Single
Dim r As Single
p = 3.1415 '定义周长率的值
r = InputBox("请输入一个圆的半径", "输入", 0) '获取输入值
s = p * r ^ 2 '面积公式
c = 2 * p * r '周长公式
MsgBox ("圆的面积为:" & s & "圆的周长为:" & c) '输出结果
End Sub