VB 輸入半徑,計算圓周長和圓面積。執行介面如下

2021-05-01 13:58:02 字數 3828 閱讀 4948

1樓:匿名使用者

private sub command1_click()if not isnumeric(text1) thenmsgbox "***"

text1.setfocus

exit sub

end if

dim r as single

r = val(text1.text)

text2.text = 3.14 * r * rend sub

private sub command2_click()if not isnumeric(text2) thenmsgbox "***"

text2.setfocus

exit sub

end if

dim r as single

r = val(text1.text)

text3.text = 2 * 3.14 * rend sub

2樓:

不瞭解isnumeric,寫了個函式

private sub command1_click()dim r as single

if isval(trim(text1.text)) thenr = val(text1.text)

text2.text = 3.14 * r * relse

msgbox "input error"

text1.setfocus

end if

end sub

private sub command2_click()dim r as single

if isval(trim(text1.text)) thenr = val(text1.text)

text3.text = 2 * 3.14 * relse

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 stringstrcmp = "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 thenisval = false

exit function

end if

next

dim str1() as string

str1 = split(str)

if ubound(str1) > 0 thenisval = false

exit function

end if

end function

vb 輸入半徑,計算圓周長和圓面積

3樓:匿名使用者

執行通過,希望對你有幫助。

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="; send sub

private sub form_load()me.show

text1.text = ""

msgbox "請輸入要計算的圓的半徑"

text1.setfocus

end sub

vb程式設計 輸入圓半徑,計算圓周長和圓面積

4樓:匿名使用者

private sub command1_click()dim pi as single

dim r as single

dim l as single

dim a as single

pi = 3.141592654

r = inputbox("輸入半徑r=")l = pi * r

a = r ^ 2 * pi / 4

print "周長=", l

print "面積=", a

end sub

5樓:匿名使用者

private sub cmdok_click()dim pi as double

pi = 3.14

if isnumeric(trim(txtr.text)) = false then

msgbox "請輸入一個合法的數"

txtr.text = ""

txtr.setfocus

exit sub

end if

txtg.text = formatnumber((2 * pi * val(txtr.text)), 2)

txta.text = formatnumber(pi * val(txtr.text) * val(txtr.text), 2)

end sub

private sub form_load()txtr.text = ""

txtg.text = ""

txta.text = ""

me.show

txtr.setfocus

end sub

-----------------

txtr:半徑 txtg:周長 txta: 面積

輸入半徑,用vb編寫計算圓面積和圓周長的程式

6樓:殺神一刀斬

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控制元件,第一個可以隨便設定,例如寫成「計算圓的周長與面積」

7樓:匿名使用者

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 * bjmsgbox "面積是" & 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

輸入半徑,計算出圓的周長和麵積,圓球的表面積和體積,並一起輸出。用C方式求解

如下 bai include define pi 3.14 void main c 根據使用者輸入的半徑,輸入以此為半徑的圓的周長和麵積 要求 計算圓的面積和周長是某類的兩個方法 親,這個是原始碼 using system using system.collections.generic using...

大圓周長是小圓一又四分之一倍,小圓面積比大圓面積少99平方釐米,求大圓面積

圓的面為s,周長為c c 2 4 s c 2 r,s 4 r,可推匯出 先設大圓周長為c,面積為s,小圓周長為c,面積為s由第一個條件知,c c 5 4 則大圓與小圓的面積比為s s 25 16,設把大圓面積分為25份,那麼小圓面積則為16份。小圓比大圓面積少25 16 9份,正好對應第二個條件小圓...

周長相等的正方形和圓,邊長與半徑的比是面積之比是

邊長與半徑的比是 2 面積之比是 4 周長相等的正方形和圓,邊長與半徑的比是 2 面積之比是 4 解 設邊長和半徑分別為a b。則4a 2丌b,得a b 2丌 4 丌 2。面積之比為a 2 丌b 2 丌 2 4丌 丌 4。解 設正方形的邊長,圓的半徑分別為x,y 4x 2 y x y 2 4 2 面...