vb编程实例2013.docx_第1页
vb编程实例2013.docx_第2页
vb编程实例2013.docx_第3页
vb编程实例2013.docx_第4页
vb编程实例2013.docx_第5页
已阅读5页,还剩17页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实验30(1)public class form1 private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click dim a as string, b as string, c as string dim x1 as single, x2 as single a = inputbox(输?入?a, 输?入?数簓据yy, , 500, 500) b = inputbox(输?入?b, 输?入?数簓据yy, , 500, 500) c = inputbox(输?入?c, 输?入?数簓据yy, , 500, 500) x1 = -b + math.sqrt(b 2 - 4 * a * c) / 2 / a x2 = -b - math.sqrt(b 2 - 4 * a * c) / 2 / a msgbox(x1= & format(x1, #.#) & x2= & format(x2, #.#) end sub private sub button3_click(byval sender as system.object, byval e as system.eventargs) handles button3.click dim x as single dim y as single x = inputbox(输?入?x) y = math.log(20) + math.abs(x - 16) msgbox(math.log(20) + math.abs(x - 16)= & y) end sub计算落体 private sub button5_click(byval sender as system.object, byval e as system.eventargs) handles button5.click const g as single = 9.81 dim v as single, o as single, t as single, s as single v = inputbox(输?入?初?速度) o = inputbox(输?入?角?度) t = 2 * v * math.sin(o * math.pi / 180) / g s = v * math.sin(2 * o * math.pi / 180) / g msgbox(落?地?所需时骸?间? & t & 落?地?时骸?运?动的?射?程 & s) end subend class实验30 (2)随机产生奇偶数并输出public class form1 private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click dim x as integer x = int(rnd() * 100) if x mod 2 = 0 then msgbox(x & 是?偶?数簓) else msgbox(x & 是?奇?数簓) end if end sub比较三个数的大小并输出 private sub button2_click(byval sender as system.object, byval e as system.eventargs) handles button2.click dim a as single, b as single, c as single, x as single, y as single a = inputbox(请?输?入?a) b = inputbox(请?输?入?b) c = inputbox(请?输?入?c) if a b then x = a y = b else x = b y = a end if if c a then x = c else if c b then y = c end if end if msgbox(最?大洙?数簓 & x & 最?小?数簓 & y) end sub计算当t120时的计算(循环语句) private sub button3_click(byval sender as system.object, byval e as system.eventargs) handles button3.click dim t as single, f as single t = inputbox(请?输?入?t) if t = 90 then y = a elseif x = 80 then y = b elseif x = 70 then y = c elseif x = 60 then y = d else y = e end if msgbox(成绩 & x & 等台?级?为a & y) end subcase选择 private sub button5_click(byval sender as system.object, byval e as system.eventargs) handles button5.click dim x as single, y as single x = inputbox(请?输?入?x) select case x case is = -1 y = x - 1 case is = 2 y = 2 * x case is = 0 then x1 = -b + math.sqrt(x) / 2 / a x2 = -b - math.sqrt(x) / 2 / a msgbox(x1= & format(x1, #.#) & x2= & format(x2, #.#) else x1 = math.sqrt(-x) / 2 / a x2 = -math.sqrt(-x) / 2 / a msgbox(x1= & -b / 2 / a & x1 & i x2= & -b / 2 / a & x2 & i) end if end sub 循环语句 实验31public class form1 dim a(19) as integer private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click dim i as integer dim n as integer dim s as single s = 0 n = inputbox(请?输?入?n) for i = 1 to n s = s + 1 / (i * (i + 1) next msgbox(s= & s) end sub求下标是奇偶数的代码 private sub button2_click(byval sender as system.object, byval e as system.eventargs) handles button2.click dim a(10) as integer dim i as integer dim x as integer dim y as integer x = 0 y = 0 for i = 1 to 10 inputbox(请?输?入?第台? & i & 个?数簓) if i mod 2 = 0 then x = x + a(i) else y = y + a(i) end if next msgbox(下?标括?为a奇?数簓的?元a素?和为a & y & 下?标括?为a偶?数簓的?元a素?和为a & x) end sub画星星图 private sub button3_click(byval sender as system.object, byval e as system.eventargs) handles button3.click dim r as integer, s as integer, c as integer, y(5) as string, j as integer, ys as string ys = r = 1 do while r = 4 c = 10 - r : s = 1 y(r) = y(r) & space(c + s) do while s = 1 c = 10 - r : s = 1 ys = ys & space(c + s) do while s 50 then x = x + 1 elseif a(i) 10 then y = y + 1 end if next msgbox(s & vbcrlf & 50万?元a以?上?的?业唉?务?人?数簓为a & x & ,10万?元a以?下?的?业唉?务?人?数簓为a & y) end sub随机产生并排序 private sub button7_click(byval sender as system.object, byval e as system.eventargs) handles button7.click dim a(19) as integer dim t as integer dim i as integer dim j as integer dim x as string dim y as string x = y = for i = 0 to 19 a(i) = int(rnd() * 100) x = x & a(i) & , next for i = 0 to 19 for j = 19 to i + 1 step -1 if a(j) = 0.000001 s = s + t i = i + 1 t = 1 / (i * (i + 1) loop msgbox(s= & s) end sub private sub button11_click(byval sender as system.object, byval e as system.eventargs) handles button11.click dim i as integer dim t as single dim s as single i = 1 t = 1 / (i * (i + 1) s = 0 do s = s + t i = i + 1 t = 1 / (i * (i + 1) loop while t = 0.000001 msgbox(s= & s) end sub private sub button14_click(byval sender as system.object, byval e as system.eventargs) handles button14.click dim a() as integer dim i as integer dim n as integer dim x as integer dim y as integer x = 0 y = 0 n = inputbox(请?输?入?数簓组哩?的?数簓量?) redim a(n) for i = 1 to n a(i) = inputbox(请?输?入?第台? & i & 个?数簓) if i mod 2 = 0 then x = x + a(i) else y = y + a(i) end if next msgbox(下?标括?为a奇?数簓的?元a素?和为a & y & 下?标括?为a偶?数簓的?元a素?和为a & x) end sub private sub button15_click(byval sender as system.object, byval e as system.eventargs) handles button15.click dim s as string dim y as string dim t as string dim a() as string dim i as integer dim j as integer dim l as integer t = y = s = inputbox(请?输?入?要癮排?序的?字?符?串?) l = len(s) redim a(l) for i = 1 to l a(i) = mid(s, i, 1) next for i = 1 to l for j = l to i + 1 step -1 if a(j) a(j - 1) then t = a(j) a(j) = a(j - 1) a(j - 1) = t end if next y = y & a(i) next msgbox(s & vbcrlf & y) end sub private sub button16_click(byval sender as system.object, byval e as system.eventargs) handles button16.click dim n as integer dim i as integer dim j as integer dim s as string dim t as string dim i_0 as integer dim j_0 as integer dim mfz_bz(9, 9) as string dim mfz(9, 9) as string n = inputbox(请?输?入?魔方?阵阶数簓 n) if n 9 or n mod 2 1 then msgbox(您输?入?的?魔方?阵阶数簓 n 不?在范?围内,?请?输?入?3-9之?间?的?奇?数簓) exit sub end if 初?始?化 for i = 1 to 9 for j = 1 to 9 mfz_bz(i, j) = 0 mfz(i, j) = next j next i mfz(1, n 2 + 1) = 1 mfz_bz(1, n 2 + 1) = 1 i_0 = 1 j_0 = n 2 + 1 for ysz = 2 to n * n if mfz(i_0, j_0) n and (mfz(i_0, j_0) mod n = 0) then i = i_0 + 1 j = j_0 elseif i_0 = 1 then i = n j = j_0 + 1 elseif j_0 = n then i = i_0 - 1 j = 1 else i = i_0 - 1 j = j_0 + 1 end if if mfz_bz(i, j) = 1 then i = i_0 + 1 j = j_0 end if mfz(i, j) = ysz mfz_bz(i, j) = 1 i_0 = i j_0 = j next ysz msgbox(魔方?阵排?列完?毕?) s = for i = 1 to 9 for j = 1 to 9 t = mfz(i, j) s = s & format(t, 0,4) next s = s & vbcrlf next msgbox(s) end subend class实验33public class form1计算油钱 private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click dim t as integer, f as single, x as string t = val(textbox1.text) f = 7.69 * t x = str$(f) + 元a label2.text = x textbox1.focus() end sub private sub form1_load(byval sender as object, byval e as system.eventargs) handles me.load textbox1.text = label2.text = end subend class判断身体健康public class form1 private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click dim x as integer if textbox1.text = then textbox1.focus() 在文?本?框1输?入?身?高? msgbox(请?输?入?身?高?) exit sub end if if textbox2.text = then textbox2.focus() 在文?本?框2输?入?体?重? msgbox(请?输?入?体?重?) exit sub end if 选?择?性?别纄 if radiobutton1.checked = false and radiobutton2.checked = false then 此?种?情况?不?会发?生? msgbox(请?选?择?被?检测a者?性?别纄) exit sub end if if radiobutton1.checked = true then x = val(textbox1.text) - 100 计?算?男d性?体?重? elseif radiobutton2.checked = true then x = val(textbox1.text) - 105 计?算?女?性?体?重? end if 判d断?体?重?是?否?超?标括?,?并显?示? if val(textbox2.text) x then label3.text = 体?重?超?标括?,?请?注痢?意癮饮?食?与?运?动!? else label3.text = 体?重?正y常 end if end sub private sub button2_click(byval sender as system.object, byval e as system.eventargs) handles button2.click 清?除y计?算?体?重?和超?标括?提?示? label3.text = : textbox1.text = : textbox2.text = radiobutton1.checked = false : radiobutton2.checked = false end sub private sub button3_click(byval sender as system.object, byval e as system.eventargs) handles button3.click end 结束?工程运?行d end sub private sub form1_load(byval sender as object, byval e as system.eventargs) handles me.load me.show() textbox1.focus() end subend classpublic class form1 dim x as integer, varstring as string private sub form1_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load textbox3.enabled = false button1.enabled = false textbox3.font = new font(宋?体?, 10, fontstyle.regular) end sub private sub button3_click(byval sender as system.object, byval e as system.eventargs) handles button3.click end end sub调整字体 private sub button2_click(byval sender as system.object, byval e as system.eventargs) handles button2.click select case true case checkbox1.checked = true and checkbox2.checked = false textbox3.font = new font(宋?体?, 10, fontstyle.bold) case checkbox2.checked = true and checkbox1.checked = false textbox3.font = new font(宋?体?, 10, fontstyle.italic) case checkbox1.checked and checkbox2.checked textbox3.font = new font(宋?体?, 10, fontstyle.bold or fontstyle.italic) case checkbox1.checked = false and checkbox2.checked = false textbox3.font = new font(宋?体?, 10, fontstyle.regular) end select end sub private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click textbox3.enabled = true textbox3.text = textbox1.text & textbox2.text if radiobutton1.checked = true then textbox3.text = textbox3.text & radiobutton1.text elseif radiobutton2.checked = true then textbox3.text = textbox3.text & radiobutton2.text end if end sub输入病例 private sub textbox1_lostfocus(byval sender as object, byval e as system.eventargs) handles textbox1.lostfocus x = len(textbox1.text) if x 6 then beep() textbox1.text = textbox1.focus() textbox3.clear() textbox3.text = 病?历?号?为a6位?数簓字? else textbox3.clear() button1.enabled = true end if end sub private sub textbox1_textchanged(byval sender as system.object, byval e as system.eventargs) handles textbox1.textchanged end sub private sub form1_shown(byval sender as object, byval e as system.eventargs) handles me.shown end subend classpublic class form1图书馆借书 private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click listbox1.items.add(combobox1.text) end sub private sub button2_click(byval sender as system.object, byval e as syste

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论