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

2021-05-01 13:58:02 字數 3763 閱讀 6982

1樓:殺神一刀斬

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

2樓:匿名使用者

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

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()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

5樓:

不瞭解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計算圓的面積和周長

6樓:匿名使用者

就兩個公式嘛

圓的周長=2×半徑×圓周率=直徑×圓周率

即:圓的周長=2πr  或πd

面積:s=πr²  或s=π(d/2)²

程式,自己弄一個textbox 1用來輸入圓的半徑textbox2用來顯示計算結果周長

textbox3用來顯示計算結果面積

新增兩個button1命名為計算圓的周長和麵積。

定義常量π,定義半徑r

然後在button1 事件中新增計算和顯示結果**即可。

public class form1

const p = 3.14

private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.

click

textbox2.clear() '清空以前計算結果textbox3.clear() '清空以前計算結果if textbox1.

text <> string.empty then  '判斷是否輸入半徑

dim r as double = textbox1.text'上面是這兩部的合併 dim r as double'                   r=textbox1.text

textbox2.text = 2 * p * rtextbox3.text = p * r * relse

msgbox("請輸入圓的半徑")

end if

end sub

end class

如果沒有輸入半徑,提示輸入半徑

c語言,編寫程式計算矩形的面積和周長,用兩個函式分別計算面積

include double zc double x,double y double mj double x,double y int main c語言編寫程式計算矩形的面積和周長,用兩個函式分別計算面積和周長。include double area double x,double y double...

C編寫程式,「求出給定半徑R的圓的面積和周長,並輸出計算結

開啟vs,檔案,新建,專案,visual c windows窗體應用程式.出現一個windows窗體,從工具欄拖一個textbox.拖一個button 雙擊button,進入事件.button1 click 周長是 area,perimeter else 不是浮點型數字 strvalue c 編寫程...

編寫C程式,從鍵盤上輸入,長和寬求矩形面積,在螢幕上輸出面積

int length,width printf 請輸入長和寬,中間用逗號分隔 printf n面積為 d length width 編寫一個c程式,從鍵盤上輸入矩形的長和寬,螢幕上顯示對應的矩形周長和麵積 include int main include main include main incl...