VB上機實驗報告

2022-08-17 05:06:04 字數 3764 閱讀 6797

實驗名稱:程式語言(vb)

實驗日期:

指導老師:

實驗地點:

姓名:班級:

學號:一、實驗名稱:實驗5 順序結構程式設計

二、實驗目的:

(1)掌握基本的輸入輸出操作(inputbox、msgbox、print使用)。

(2)掌握順序結構的程式設計方法。

三、實驗內容:

1.課本的3.3、3.4、3.5、3.6、3.7、3.8

2.用圖形、影象框控制項實現**切換和**放大縮小。

3.根據提示,補充下列程式段,並在vb環境下除錯:

(1)雞兔同籠問題。

(2)計算三角形的面積。

四、實驗步驟及結果:

1、3.3:

private sub command1_click()

dim x as integer, y as integer

dim s1 as string, s2 as string

x = 2: y = 1

s1 = x & "+" & y & "=" & x + y

s2 = x & "-" & y & "=" & x - y

msgbox s1 & vbcrlf & s2, , "輸出"

end sub

3.4:

private sub command1_click()

dim x as integer, y as integer

x = inputbox("請輸入第1個整數", "輸入", 0) '

y = inputbox("請輸入第2個整數", "輸入", 0) '

print "第1個數為:" & x

print "第2個數為:" & y

print "和=" & x + y

print "差=" & x - y

end sub

3.5:

private sub command1_click()

dim r as single, h as single

dim area as single, v as single

r = inputbox("請輸入半徑")

h = inputbox("請輸入高度")

area = 2 * 3.14 * r * r + 2 * 3.14 * r * h

v = 3.14 * r * r * h

print "圓柱體的半徑為:" & r; "高為:" & h

print "表面積為:" & area

print "體積為:" & v

end sub

3.6:

private sub command1_click()

dim a as single, b as single, c as single '

dim s as single, area as single '

a = val(text1)

b = val(text2)

c = val(text3)

s = (a + b + c) / 2 '

area = sqr(s * (s - a) * (s - b) * (s - c))

label2 = "三角形的面積為:" & area '

end sub

3.7:

private sub command1_click()

dim a as integer, b as integer, t as integer

a = text1

b = text2

t = a

a = b

b = t

label2 = "交換後的值為:" & a & "," & b

end sub

3.8:

private sub command1_click()

dim x as integer, s as integer

dim a as integer, b as integer

dim c as integer, d as integer

x = inputbox("請輸入乙個四位整數")

a = x mod 10

b = x \ 10 mod 10

c = x \ 100 mod 10

d = x \ 1000

s = a + b + c + d

print x; "的各位數字之和為:"; s

end sub

2、用圖形、影象框控制項實現**切換和**放大縮小:

**切換:

private sub command1_click()

= loadpicture( + "\春.jpg")

end sub

private sub command2_click()

= loadpicture( + "\夏.jpg")

end sub

private sub command3_click()

= loadpicture( + "\秋.jpg")

end sub

private sub command4_click()

= loadpicture( + "\冬.jpg")

end sub

private sub command5_click()

= loadpicture("")

end sub

**放大縮小:

private sub command1_click()

= true

= * 2

= * 2

end sub

private sub command2_click()

= true

= / 2

= / 2

end sub

private sub command3_click()

= false

end sub

3、(1)雞兔同籠問題:

private sub command1_click()

dim h as integer

dim f as integer

dim x as integer

dim y as integer

h = val(

f = val(

x = (4 * h - f) / 2

y = (f - 2 * h) / 2

= x= yend sub

(2)計算三角形的面積:

private sub command1_click()

dim a as single

dim b as single

dim c as single

dim s as single

dim area as single

a =b =c =s = (a + b + c) / 2

area = sqr(s * (s - a) * (s - b) * (s - c))

= area

end sub

五、實驗分析及總結:

(1)通過幾次vb上機實驗,我發現只要**不寫錯,除錯結果通常都會成功。因此,上課時應當認真聽講,下課時多看書,了解**的意義,仔細編寫,就會除錯成功。

(2)真理**於實踐,我們不僅要上課聽講,更應該認真對待每一次上機實驗。從實驗中積累經驗,及時查漏補缺,提高自己的能力。

(3)付出總會有收穫,只要自己認真的做了,結果總不會令你失望的,經過多次上機實驗,我發現自己對vb這門課的興趣越來越濃厚。興趣是學習一切的最好老師,我想先我一定會慢慢的進步。

VB實驗報告

台州學院 vb程式設計 實驗報告 實驗二 visual basic 程式設計基礎 班級 14生科2 學號 1431210034 姓名 何敏 實驗日期 20150331 一 實驗目的和要求 1 掌握基本語句 print語句 賦值語句 dim語句等 的使用 2 掌握表示式的正確書寫方法及函式 運算子的正...

VB實驗報告

浙江大學城市學院實驗報告 課程名稱vb程式設計基礎與實驗 實驗專案名稱實驗 四 分支結構程式設計 學生姓名專業班級學號 實驗成績指導老師 簽名日期 一.實驗目的和要求 1.掌握單分支與雙分支條件語句if的使用。2.掌握多分支條件語句的使用。3.掌握情況語句select case的使用及其與多分支條件...

VB實驗報告

內蒙古工業大學能動學院 課程名稱 高階語言程式設計 vb 實驗名稱 選擇 迴圈 陣列和過程綜合程式設計 實驗型別 驗證性 綜合性 設計性 實驗室名稱 校計算中心 班級 學號 姓名 組別 同組人成績 實驗日期 實驗報告撰寫要求 一 實驗前用預習報告紙撰寫預習報告,預習報告包括以下內容 1 實驗目的 2...