输入半径,用VB编写计算圆面积和圆周长的程序
为保证程序运行的正确,对输入的半径进行合法检查,数据检查调用ISNUMERIC函数,利用MSGBOX先是出错信息,结果保留两位小数。要求面积和周长用两个COMMAND完成...
为保证程序运行的正确,对输入的半径进行合法检查,数据检查调用ISNUMERIC函数,利用MSGBOX先是出错信息,结果保留两位小数。要求面积和周长用两个COMMAND完成。半径用一个标签控制输入。谢谢。
展开
2个回答
展开全部
Private Sub Label2_Click()
const PI = 3.14159
Dim r As Single, i As Single, s As Single
r = InputBox("请输入半径:", "输入半径")
i = 2 * PI * r
s = PI * r ^ 2
Label2 = Label2 & r
Label3 = Label3 + Str(i)
Label4 = Label4 + Str(s)
End Sub
当然你要有四个Label控件,第一个可以随便设置,例如写成“计算圆的周长与面积”
const PI = 3.14159
Dim r As Single, i As Single, s As Single
r = InputBox("请输入半径:", "输入半径")
i = 2 * PI * r
s = PI * r ^ 2
Label2 = Label2 & r
Label3 = Label3 + Str(i)
Label4 = Label4 + Str(s)
End Sub
当然你要有四个Label控件,第一个可以随便设置,例如写成“计算圆的周长与面积”
推荐于2018-03-22
展开全部
Private Sub Command1_Click()
Dim bj As Single
Dim zz As Single
Dim mj As Single
bj = CSng(Text1.Text)
If bj <= 0 Then
MsgBox "你的输入有误"
Exit Sub
End If
mj = 3.1415 * bj * bj
MsgBox "面积是" & Format(mj, "0.00")
End Sub
Private Sub Command2_Click()
Dim bj As Single
Dim zz As Single
Dim mj As Single
bj = CSng(Text1.Text)
If bj <= 0 Then
MsgBox "你的输入有误"
Exit Sub
End If
zz = 2 * bj * 3.1415
MsgBox "周长是" & Format(zz, "0.00")
End Sub
Dim bj As Single
Dim zz As Single
Dim mj As Single
bj = CSng(Text1.Text)
If bj <= 0 Then
MsgBox "你的输入有误"
Exit Sub
End If
mj = 3.1415 * bj * bj
MsgBox "面积是" & Format(mj, "0.00")
End Sub
Private Sub Command2_Click()
Dim bj As Single
Dim zz As Single
Dim mj As Single
bj = CSng(Text1.Text)
If bj <= 0 Then
MsgBox "你的输入有误"
Exit Sub
End If
zz = 2 * bj * 3.1415
MsgBox "周长是" & Format(zz, "0.00")
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询