VB输入半径,计算圆周长和圆面积。

2024-11-22 09:00:13
推荐回答(2个)
回答1:

运行通过,希轿悄望对者帆塌你有帮助。
Private Sub Command1_Click()
Dim r As Double
r = Val(Text1.Text)
c = 2 * 3.14 * r
s = 3.14 * r * r
Print "周长c="; c; "面积s="; s
End Sub

Private Sub Form_Load()
Me.Show
Text1.Text = ""
MsgBox "首圆请输入要计算的圆的半径"
Text1.SetFocus
End Sub

回答2:

dim r as single
dim c as single
dim s as single
if isnumeric(text1.text) = true then
r = text1.text
c = formatnumber(2 * 3.14 * r, 2)
s = formatnumber(3.14 * r ^ 2, 2)
print "圆的周长、面积分别为:", c, s
else
msgbox "你输入的数错误衫凯!"
text1.setfocus
text1.selstart = 0
text1.sellength = len(text1.text)
end if
想象着写的,这边没VB,自己调或扒唤试下此游吧。