VB語(yǔ)言程序設(shè)計(jì)課后編程及上機(jī)調(diào)試參考答案_第1頁(yè)
VB語(yǔ)言程序設(shè)計(jì)課后編程及上機(jī)調(diào)試參考答案_第2頁(yè)
VB語(yǔ)言程序設(shè)計(jì)課后編程及上機(jī)調(diào)試參考答案_第3頁(yè)
VB語(yǔ)言程序設(shè)計(jì)課后編程及上機(jī)調(diào)試參考答案_第4頁(yè)
VB語(yǔ)言程序設(shè)計(jì)課后編程及上機(jī)調(diào)試參考答案_第5頁(yè)
已閱讀5頁(yè),還剩14頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、vb語(yǔ)言程序設(shè)計(jì)課后編程及上機(jī)調(diào)試參考答案ex0101private sub label1_click() caption = "練習(xí)" command1.caption = "確定" label1.fontbold = true label1.autosize = true label1.caption = "visual basic程序設(shè)計(jì)教程"end subex0102private sub command1_click() txt.text = "我有電腦"end subprivate sub comman

2、d2_click() txt.text = "我沒(méi)有電腦"end subprivate sub command3_click() txt.text = "" '一對(duì)雙撇號(hào),中間不留空end subex0104private sub command1_click() dim x as single x = val(text1.text) text2.text = 15 * xend subex0202private sub form_click() dim r as single, s as single r = 4.6 s = 3.14159 *

3、 r 2 text1.text = "圓的面積為" & send subex0204private sub command1_click() '"最大化"按鈕 form1.windowstate = 2 '最大化end subprivate sub command2_click() '"還原"按鈕 form1.windowstate = 0 '還原end subprivate sub command3_click() '"最小化"按鈕 form1.windowstat

4、e = 1 '最小化end subex0205private sub command1_click() dim x as single dim y as single x = val(text1.text) y = val(text2.text) text3.text = x * x + y * yend subex0206private sub command1_click() dim x as string x = text1.text text2.text = left(x, 1) + right(x, 1)end subex0301private sub form_load()

5、 dim x as integer, y as integer dim a as integer, b as integer, c as integer x = val(inputbox("請(qǐng)輸入一個(gè)三位數(shù)") a = int(x / 100) '求百位數(shù) b = int(x / 10) - a * 10 '求十位數(shù) c = x mod 10 '求個(gè)位數(shù) show y = c * 100 + b * 10 + a '生成倒序數(shù) print x; "倒序數(shù)為:" y '顯示倒序數(shù)end subex0302privat

6、e sub command1_click() n = val(text1.text) randomize x = int(1 + n * rnd) label1.caption = "第一個(gè)隨機(jī)數(shù)" + str(x) x = int(1 + n * rnd) label2.caption = "第二個(gè)隨機(jī)數(shù)" + str(x) x = int(1 + n * rnd) label3.caption = "第三個(gè)隨機(jī)數(shù)" + str(x)end subex0303private sub cmd1_click() lab1.visible

7、 = true lab1.caption = "您已下達(dá)顯示命令"end subprivate sub form_click() cmd1.visible = trueend subex0304private sub form_keypress(keyascii as integer) show print "輸入字符:" chr(keyascii), "ascii碼為;" keyasciiend subprivate sub form_dblclick() clsend subex0305private sub form_load(

8、) x = msgbox("在這里顯示提示信息", 4 + 0, "請(qǐng)確認(rèn)") x = msgbox("在這里顯示" + chr(13) + "提示信息", 3 + 0, "請(qǐng)確認(rèn)") x = msgbox("在這里顯示" + chr(13) + "提示信息", 2 + 16 + 0, "請(qǐng)確認(rèn)")end subex0401private sub form_load() dim x as long, s as string x = in

9、putbox("輸入一個(gè)整數(shù)(135000)") s = "奇數(shù)" if x mod 2 = 0 then s = "偶數(shù)" msgbox send subex0402private sub command1_click() dim a as single, b as single dim c as single, d as single dim m as single, n as single, x as single show a = val(text1.text) b = val(text2.text) c = val(text

10、3.text) d = val(text4.text) if a > b then '求a、b中的較大數(shù) m = a else m = b end if if c > d then '求c、d中的較大數(shù) n = c else n = d end if if m > n then '求m、n中的較大數(shù) x = m else x = n end if text5.text = xend subex0403private sub command1_click() dim t as string, p as string t = mid(text1.text,

11、 5, 1) select case t case "2" p = "博士生" case "3" p = "碩士生" case "4" p = "本科生" case "5" p = "??粕?quot; case else p = "無(wú)效學(xué)號(hào)" end select text2.text = left(text1.text, 2) + "級(jí)" text3.text = pend subex0404priva

12、te sub command1_click() r = 0: g = 0: b = 0 if check1.value = 1 then r = 255 end if if check2.value = 1 then g = 255 end if if check3.value = 1 then b = 255 end if label1.backcolor = rgb(r, g, b)end subprivate sub command2_click() endend subex0405private sub form_load() labclk.caption = "0"

13、; labclk.alignment = 1 labclk.borderstyle = 1 labclk.fontsize = 22 labclk.fontname = "黑體" timclk.interval = 1000end subprivate sub timclk_timer() labclk.caption = val(labclk.caption) + 1end subex0406private sub form_load() command1.enabled = false command2.enabled = falseend subprivate sub

14、 text1_mouseup(button as integer, shift as integer, x as single, y as single) if text1.sellength > 0 then command1.enabled = true end ifend subprivate sub command1_click() command1.enabled = true command2.enabled = trueend subprivate sub command2_click() text2.text = text1.seltext command1.enable

15、d = false command2.enabled = falseend subex0501private sub form_load() dim k as integer, s as integer, t as integer s = 0 for k = 1 to 100 step 2 s = s + k next k show print "1100范圍內(nèi)的奇數(shù)和:" send subex0502private sub form_load() dim s as single show s = 0 for k = 1 to 200 s = s + k / (1 + k

16、* k) next k print int(s * 10 + 0.5) / 10end subex0503private sub form_load() show k = 2 s = 0 do while k < 101 s = s + k * (k - 1) k = k + 2 loop print send subex0504private sub form_load() dim k as integer, a as integer, b as integer dim c as integer, n as integer show n = 0 print "三位數(shù)的水仙花數(shù)

17、是:" for k = 100 to 999 a = int(k / 100) b = int(k - 100 * a) / 10) c = k mod 10 if a * a * a + b * b * b + c * c * c = k then print k n = n + 1 end if next k print "一共有" & n & "個(gè)水仙花數(shù)"end subex0505private sub form_load() show for k = 1000 to 9999 if k mod 78 = 0 then

18、a = int(k / 1000) b = int(k / 100) - 10 * a c = int(k / 10) - 100 * a - 10 * b d = k mod 10 if a = b and c = d then print k end if end if next kend subex0506private sub command1_click() dim s as string, y as string dim x as string, t as string s = text1.text: y = "" for k = 1 to len(s) x =

19、 mid(s, k, 1) t = ucase(x) if t >= "a" and t <= "z" then y = y + x end if next k text2.text = yend subex0507private sub command1_click() '"顯示"按鈕單擊事件 fontsize = 12 cls for i = 0 to list1.listcount - 1 '逐項(xiàng)判斷 if list1.selected(i) then '真時(shí)為選定 print list1.l

20、ist(i) end if next iend subex0508private sub form_load() show for a = 1 to 9 for b = 1 to 9 for c = 1 to 9 for d = 1 to 9 x = a * 1000 + b * 100 + c * 10 + d y = b * 1000 + a * 100 + a * 10 + c z = d * 100 + d * 10 + a if x - y = z then print "a=" & a & ",b=" & b &

21、; ",c=" & c & ",d=" & d end if next d next c next b next aend subex0601private sub command1_click() dim a(10) as integer, min as integer, pos as integer randomize for i = 1 to 10 a(i) = int(rnd * 90 + 10) print a(i); next i print min = a(1) pos = 1 for k = 2 to 10 if

22、a(k) < min then min = a(k) pos = k end if next k print "最小數(shù):" min, "位置:" posend subex0602private sub form_load() dim a as variant, b as variant dim c(8) as integer a = array(3, 4, 2, 1, 5, 7, 8, 11, 13) b = array(10, 6, 12, 9, 13, 8, 8, 1, 16) for k = 0 to 8 c(k) = a(k) + b(k)

23、 next k show for k = 0 to 8 print c(k) next kend subex0603private sub form_load() dim d() as integer dim k as integer, t as integer, m as integer dim h as integer, n as integer n = val(inputbox("請(qǐng)輸入數(shù)組個(gè)數(shù)n:") redim d(n) show print "處理前數(shù)據(jù) :" randomize for k = 1 to n d(k) = int(101 *

24、 rnd - 50) print d(k); next k print m = int(n / 2) for k = 1 to m h = n - k + 1 t = d(h): d(h) = d(k): d(k) = t next k print "處理的結(jié)果 :" for k = 1 to n print d(k); next kend subex0604private sub form_load() dim a(8, 8) as integer, n as integer dim s as long, i as integer, j as integer show r

25、andomize n = 8 for i = 1 to n for j = 1 to n x = int(90 * rnd + 10) '產(chǎn)生一個(gè)隨機(jī)數(shù) a(i, j) = x next j next i s = 0 for i = 1 to n for j = 1 to n s = s + a(i, j) next j next i print "所有元素之和;" s print for i = 1 to n s = 0 for j = 1 to n s = s + a(i, j) next j print "第" i; "行元素之和

26、;" s next i print s = 0 for i = 1 to n s = s + a(i, i) next i print "主對(duì)角線元素之和;" s print s = 0 for i = 1 to n for j = 1 to n if i = 1 or i = n or j = 1 or j = n then s = s + a(i, j) end if next j next i print "所有靠邊元素之和;" send subex0605option base 1private sub form_load() dim

27、a(8, 8) as integer, n as integer dim max as integer, r as integer, c as integer show randomize n = 8 for i = 1 to n for j = 1 to n x = int(900 * rnd + 100) '產(chǎn)生一個(gè)隨機(jī)數(shù) a(i, j) = x print x; next j print next i max = 0: r = 1: c = 1 print for i = 1 to n for j = 1 to n if a(i, j) > max then '判斷

28、有無(wú)更大數(shù) max = a(i, j): r = i: c = j end if next j, i print "最大值為:" max print "位于行:" r, "列:" cend subex0606dim n as integerprivate sub cmd1_click() n = n + 1 if n = 3 then n = 0 opt1(n).value = trueend subprivate sub form_load() n = 1end subex0607private sub form_load() di

29、m a(20) as integer randomize a(1) = int(10 + 90 * rnd) k = 1 do while k < 20 x = int(10 + 90 * rnd) f = 0 for j = 1 to k if x = a(j) then f = 1 exit for end if next j if f = 0 then k = k + 1 a(k) = x end if loop show for j = 1 to 20 print a(j) next jend subex0701private sub form_click() dim s as

30、long s = 0 for k = 1 to 10 s = s + jc(k) next k print send subfunction jc(n) as long dim t as long t = 1 for k = 1 to n t = t * k next k jc = tend functionex0702private sub form_load() dim a as single, b as single, c as single dim d as single, m as single, n as single show a = val(inputbox("輸入第

31、1個(gè)數(shù)") b = val(inputbox("輸入第2個(gè)數(shù)") c = val(inputbox("輸入第3個(gè)數(shù)") d = val(inputbox("輸入第4個(gè)數(shù)") m = max(a, b) '求a、b中的較大數(shù) n = max(c, d) '求c、d中的較大數(shù) print "最大數(shù)為:" & max(m, n) '求m、n中的較大數(shù)end subfunction max(x, y) as single if x > y then max = x else

32、max = y end ifend functionex0703private sub command1_click() dim d(5) as single, m as single for k = 0 to 5 d(k) = val(text1(k).text) next k call max(d(0), d(1), d(2), m) call max(m, d(3), d(4), m) call max(m, m, d(5), m) text2.text = mend subex0704private sub form_load() dim x as long show x = val(

33、inputbox("輸入一個(gè)數(shù)") print x; "的位數(shù)為:" fnws(x)end subfunction fnws(x as long) as integer dim n as integer n = 1 do while x 10 > 0 n = n + 1 x = x 10 loop fnws = nend functionex0705private sub c1_click() form1.hideend subex0705aprivate sub c2_click() form1.showend subex0706dim n as

34、 integerprivate sub command1_click() usern = trim(text1.text) passw = trim(text2.text) if usern = "username" and passw = "password" then form1.hide form2.show else n = n + 1 text1.setfocus if n = 3 then form1.hide form3.show end if end if text1.text = "" text2.text = &q

35、uot;"end subex0706aprivate sub command1_click() form2.hide form1.showend subex0906bprivate sub command1_click() unload form1 unload form2 unload form3 endend subex0802private sub form_load() dim i as integer, j as integer show for i = 1 to 12 print string(20 - i, 32); '輸出當(dāng)前行左邊的空格,分號(hào)表示下一輸出項(xiàng)緊

36、接輸出 for j = 1 to 2 * i - 1 '輸出2*i-1個(gè)字符 if j <= i then '按左、右兩邊指定輸出字符 k = j '左邊輸出的字符 else k = 2 * i - j '右邊輸出的字符 end if if k > 9 then k = k + 7 '字母的ascii碼比數(shù)字大7 print chr(k + 48); '以字符格式輸出 next j print '換行 next iend subex0803dim t as single, f as integerprivate sub com

37、mand1_click() '“產(chǎn)生原稿文”按鈕 randomize s = "" for k = 1 to 30 x = chr(int(rnd * 26) + 97) '隨機(jī)產(chǎn)生小寫(xiě)字母 s = s + x next k text1.text = s '顯示在文本框中 text2.text = "" text2.locked = false '允許錄入 text2.setfocus '設(shè)置焦點(diǎn) text3.text = "" text4.text = "" f = 0 &

38、#39;第1次按鍵標(biāo)記,0表示未按鍵end subprivate sub command2_click() '“結(jié)束”按鈕 endend subprivate sub text2_keyup(keycode as integer, shift as integer) dim c as integer, k as integer if f = 0 then '第1次按鍵時(shí),開(kāi)始計(jì)時(shí) t = timer '用t保存第1次按鍵的時(shí)間 f = 1 '1表示已按鍵和進(jìn)入錄入過(guò)程 end if if len(text2.text) < 30 then text3.te

39、xt = round(timer - t, 1) & "秒" '顯示用戶當(dāng)前所用時(shí)間 else c = 0 for k = 1 to 30 '統(tǒng)計(jì)錄入正確的字母?jìng)€(gè)數(shù) if mid(text1.text, k, 1) = mid(text2.text, k, 1) then c = c + 1 end if next k text2.locked = true '禁止錄入 text4.text = round(c / 30 * 100, 2) & "%" '顯示準(zhǔn)確率 end ifend subex0901p

40、rivate sub command1_click() open "靜夜思.txt" for input as #1 do while not eof(1) '文件未結(jié)束時(shí),循環(huán) input #1, x list1.additem x loop close #1end subex0902dim d(1 to 20) as integerprivate sub command1_click() '"產(chǎn)生隨機(jī)數(shù)" for i = 1 to 20 d(i) = int(1 + 99 * rnd) list1.additem d(i) next

41、iend subprivate sub command2_click() '"保存" open "myfile4.txt" for output as #1 for i = 1 to 20 write #1, d(i) next i close #1end subprivate sub command3_click() '"讀出" open "myfile4.txt" for input as #1 do while not eof(1) input #1, x list2.additem x lo

42、op close #1end subprivate sub command4_click() '"結(jié)束" endend subex0903private sub form_load() show for k = 1 to 6 fn = ".第7章ex070" & k & ".vbp" if dir(fn) = "" then print mid(fn, 4) & "未編寫(xiě)!" else print mid(fn, 4) & "已編寫(xiě)!" end if next kend subex0904private sub form_load() chedir = "c:documents and settingslinmy documentsfsodir" if dir(chedir, 16) = "" then mkdir chedir end if chefile = "c:wi

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論