vb上机答案全部_第1页
vb上机答案全部_第2页
vb上机答案全部_第3页
vb上机答案全部_第4页
vb上机答案全部_第5页
已阅读5页,还剩30页未读 继续免费阅读

下载本文档

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

文档简介

1、实验一 1. 输出文本对象对象名称属性属性值说明窗体Form1caption输出文本标题width3000窗体宽度Height1500窗体高度maxbuttonfalse无最大化按钮Minbuttonfalse无最小化按钮Font宋体、粗体、四号字体、字号、字形Private sub form_click()Form1.print “程序设计基础教程”End subPrivate sub form_dblclick()Form1.clsEnd sub2.对象对象名称属性属性值说明窗体Form1Caption乘法运算标题标签Label1Caption被乘数标题Label2caption乘数标题文

2、本框Text1Text文本内容Text2TextText3Text命令按钮Command1Caption乘积标题Private Sub Command1_click()Dim a as single,b as single,c as singlea=val(text1.text)b=val(text2.text)c=a*btext3.text=str(c)end sub3.对象对象名称属性属性值说明窗体Form1Caption数值运算标题标签Label1Caption请输入整数n标题文本框Text1TextText2Text命令按钮Command1Caption立方根标题Private Sub

3、 Command1_click()Dim n as integer,a as singlen=val(text1.text)a= n(1/3)text2.text=str(a)end sub4.对象对象名称属性属性值说明窗体Form1Caption文本显示标题文本框Text1Text命令按钮Command1Caption显示标题Command2Caption清空标题Private Sub Command1_click()Text1.text=“visual basic 程序设计”end subPrivate Sub Command2_click()Text1.text=“”end sub5.对

4、象对象名称属性属性值说明窗体Form1Caption字符串运算标题文本框Text1TextText2TextText3Text命令按钮Command1Caption左子串标题Command2Caption长度标题Private Sub Command1_click()Text2.text=left(text1.text,5)end subPrivate Sub Command2_click()Text3.text=len(text1.text)end sub6.对象对象名称属性属性值说明窗体Form1captionwidthHeightcontrolboxtrue无控制菜单栏命令按钮Comma

5、nd1CaptionCommand2CaptionPrivate Sub Command1_Click()Form1.Move 0, 0End SubPrivate Sub Command2_Click()Form1.Height = Form1.Height * 1.2Form1.Width = Form1.Width * 1.2End Sub7.对象对象名称属性属性值说明窗体Form1Caption标签Label1CaptionLabel2captionLabel3caption文本框Text1TextText2TextText3Text命令按钮Command1Caption通用声明Con

6、st pi as single=3.14159Command1_click()Dim a as single,b as single,c as single,s as singlea=val(text1.text)b=val(text2.text)c=val(text3.text)s=a*b*sin(c*pi)/180)/2text4.text=round(s ,2)end sub实验二 顺序1.对象对象名称属性属性值说明窗体Form1Caption圆球体积标题标签Label1Caption圆球半径标题Label2captionborderstyle1- fixedsingle有边框命令按钮C

7、ommand1Caption体积标题文本框Text1Text通用声明Const pi as single=3.14159Private Sub Command1_click()Dim r as single,v as singler=val(text1.text)v=4/3 *pi*r3label1.caption=format(v, “0.00”)end sub2.对象对象名称属性属性值说明窗体Form1Caption平均成绩标题标签Label1Caption语文成绩标题Label2Caption数学成绩标题Label3Caption英语成绩标题命令按钮Command1Caption平均分标

8、题文本框Text1TextText2TextText3TextText4Textlockedtrue内容不可编辑Private Sub Command1_click()Dim a as single,b as single,c as single,d as singlea=val(text1.text)b=val(text2.text)c=val(text3.text)d=(a+b+c)/3text4.text=format(d, “0.00”)end sub3.对象对象名称属性属性值说明窗体Form1Caption文本编辑标题文本框Text1TextScrollbars2- vertical

9、具有垂直滚条MultilineTrue多行显示lockedTrue命令按钮Command1Caption编辑&EAlt+e或单击Command2Caption保存&SAlt+s或单击EnabledFalse按钮不可用Private Sub Command1_click()Text1.locked=falseEnd subPrivate Sub Text1_changeCommand2.enable=trueEnd subPrivate Sub Command_click()Text1.locked=trueCommand2.enable=falseEnd sub4.对象对象名称

10、属性属性值说明窗体Form1Caption登录界面标题文本框Text1TextFont粗体、四号Tabindex0文本框获得焦点Alignment2-center内容居中命令按钮Command1Caption登录标题DefaultTrueEnder键Command2Caption退出标题CancelTrueEscCommand1_click()Text1.text=“欢迎光临”End subCommand2_click()Text1.text=“谢谢再见”End sub5.对象对象名称属性属性值说明窗体Form1Caption文本复制标题文本框Text1TextScrollbars2-vert

11、ical垂直滑块MultilineTrue自动换行命令按钮Command1Caption选择标题Command2Caption复制标题标签Label1Captionborderstyle1-Fixed single 有边框Command1_click()Text1.selstart=8Text1.sellength=9 End subCommand2_click()Label2.caption=text1.seltextEnd sub6.对象对象名称属性属性值说明窗体Form1Caption标签Label1CaptionLabel2Caption文本框Text1TextText2TextTex

12、t3TextText4Text命令按钮Command1CaptionnameCmd1按钮名称Command2Captionname通用声明Const pi as single=3.14159Dim r as single,h as singlePrivate Sub Command click()Dim s as singler=text1.texth=text2.texts=2*pi*r2+2*pi*r*htext3.text=format(s, “0.000”)end subPrivate Sub command2 click()dim v as singlev=pi*r2*htext4.

13、text=format(v, “0.000”)end sub7.对象对象名称属性属性值说明窗体Form1Caption文本框Text1TextText2Text标签Label1Captionborderstylename命令按钮Command1CaptionCommand2Caption通用声明Dim a as string,b as stringPrivate Sub Command1_click()a=text1.textb=text2.texttext3.text=“a” & “b”end subPrivate Sub command2_click()dim t as strin

14、ga=text1.textb=text2.textt=aa=bb=ttext1.text=atext2.text=b label1.caption=“交换成功”end sub实验三 选择1.对象对象名称属性属性值说明窗体Form1Caption标签Label1CaptionLabel2Captionborderstyle命令按钮Command1Caption文本框Text1TextCommand1_clickDim n as integerIf (n mod 3=0 )and (n mod 7=0 ) thenLabel2.caption=“Yes”ElseLabel2.caption=“No

15、”End ifEnd sub2.对象对象名称属性属性值说明窗体Form1Caption标签Label1CaptionLabel2Caption文本框Text1TextText2TextText3Text命令按钮Command1CaptionDim x as single,y as singlex=text1.texty=text2.textif x>0 and y>0 thentext3.text=“第一象限”elseif x<0 and y>0 thentext3.text=“第二象限”elseif x<0 and y<0 thentext3.text=“

16、第三象限”else x>0 and y<0 thentext3.text=“第四象限”end ifend sub3.对象对象名称属性属性值说明窗体Form1Caption标签Label1Caption命令按钮Command1Caption文本框Text1TextText2TextText3TextText4TextCommand1_clickDim a as single,b as single,c as single,d as singlea=text1.textb=text2.textc=text3.textd=a+b+cif d>=270 thenif d>=28

17、5 thentext4.text=“Gold Medal”elsetext4.text=“Silver Medal”end ifelseif d>240 thentext4.text=“Bronze Medal”else if a>95 or b>95 or c>95 then text4.text=“Honor Medal” else text4.text=“No Medal” end ifend ifend sub 4.对象对象名称属性属性值说明窗体Form1Caption文本框Text1TextAlignmentfont框架Frame1Caption学历标题单选按

18、钮Option1Caption博士标题Option2CaptionOption3CaptionOption1_clickText.text=“我是博士生”End subOption2_clickText.text=“我是硕士生”End subOption3_clickText.text=“我是本科生”End sub5.对象对象名称属性属性值说明窗体Form1Caption标签Label1CaptionborderstyleFontAlignment复选框Check1caption下划线标题Check1captionPrivate Sub Check1_Click()If Check1.Valu

19、e ThenLabel1.FontUnderline = TrueElseLabel1.FontUnderline = FalseEnd IfEnd SubPrivate Sub Check2_Click()If Check2.Value ThenLabel1.FontStrikethru = TrueElseLabel1.FontStrikethru = FalseEnd IfEnd Sub6.对象对象名称属性属性值说明窗体Form1Caption标签Label1Caption文本框Text1TextText2Textenablefalse不可操作命令按钮Command1CaptionCom

20、mand1_clickDim n as singlen=text1.textif n=<4 thentext2.text=format(10,“0.0”)elseif n>4 and n<=15 thentext2.text=format(10+1.2*(n-4),“0.0”)elsetext2.text=format(1.8*n,“0.0”)end ifend sub7.对象对象名称属性属性值说明窗体Form1Caption标签Label1CaptionLabel2Caption文本框Text1TextText2TextPasswordchar*文本显示*命令按钮Comma

21、nd1Caption单选按钮Option1CaptionNameOp1名字Option2CaptionNamevaluetrue选中标签Label3CaptionBorderstylefontfontcolor红色前景色Command1_clickIf text1.text=“Teacher” then If text2.text=“123456” then Label3.caption=“登录成功”Else Label3.caption=“密码不正确” End ifElseif text1.text=“Student” thenIf text2.text=“654321” then Labe

22、l3.caption=“登录成功”Else Label3.caption=“密码不正确” End ifElseLabel3.caption=“用户未注册”End ifEnd sub实验四 循环1对象对象名称属性属性值说明窗体Form1Caption标签Label1Caption命令按钮Command1Caption文本框Text1Text标签Label2CaptionBorderstylePrivate Sub Command1_Click()Dim n As Integer, i As Integer, a As Longn = Text1.Texta = 0For i = 1 To n I

23、f (i Mod 3 = 0) And (i Mod 7 <> 0) Then a = a + i End If Next i Label1.Caption = aEnd Sub2.对象对象名称属性属性值说明窗体Form1Caption标签Label1CaptionLabel2Caption文本框Text1TextText2TextText3Text命令按钮Command1CaptionPrivate Sub Command1_Click()Dim n As Integer, m As Integer, i As Integern = Text1.Text n=val(text1.

24、text)m = Text2.Text m=val(text2.text)If m >= n Then for i=n to 1 step -1 For i = n To 1 Step -1 if n mod i=0 and m mod i=0 then If (m Mod i = 0) And (n Mod i) = 0 Then text3.text=str(i) Text3.Text = I exit for Exit For end if End If next i Next iElse For i = m To 1 Step -1 If (m Mod i = 0) And (n

25、 Mod i = 0) Then Text3.Text = i Exit For End If Next iEnd IfEnd Sub3.对象对象名称属性属性值说明窗体Form1Caption标签Label1CaptionLabel2Caption文本框Text1TextText2TextText3Text命令按钮Command1CaptionPrivate Sub Command1_Click()Dim n As Integer, m As Integer, i As Integer, a As Integer, s As Integer, flag As Boolean m = Text1

26、.Text n = Text2.Text s = 0For a = m To n flag = True For i = 2 To a - 1 If a Mod i = 0 Then flag = False Exit For End IfNext iIf flag = True Then s = s + aNext aText3.Text = sEnd Sub4.对象对象名称属性属性值说明窗体Form1Caption标签Label1CaptionHeightWidthleft100左边距Borderstyle命令按钮Command1CaptionCommand2Caption计时器Timer

27、1Internal1000时间间隔为1秒EnableFalse非激活状态Private Sub Command1_Click()Timer1.Enabled = TrueEnd SubPrivate Sub Command2_Click()Timer1.Enabled = FalseLabel1.Left = 100End SubPrivate Sub Timer1_Timer()Label1.Left = Label1.Left + 100End Sub5.对象对象名称属性属性值说明窗体Form1Caption标签Label1CaptionBorderstyle水平滚条Hscroll1Max

28、100最大值Min1最小值value10当前值命令按钮Command1CaptionCommand2Caption文本框Text1TextPrivate Sub Command1_Click()Dim n As Single, i As Single, a As Single, s As Singlen = Label1.Captions = 0For i = 1 To n For a = 1 To i s = s + a Next aNext iText1.Text = sEnd SubPrivate Sub HScroll1_Change()Label1.Caption = HScroll

29、1.ValueEnd Sub6.对象对象名称属性属性值说明窗体Form1Caption标签Label1CaptionBorderstyle命令按钮Command1CaptionCommand2Caption文本框Text1TextPrivate Sub Command1_Click()Dim s As Single, n As Long, t As Long, i As Longs = Text1.Textt = 1For i = 1 To Len(s) If Right(s, 1) = "1" Then n = n + t End If t = t * 2 s = Lef

30、t(s, Len(s) - 1) Next i Label1.Caption = nEnd SubPrivate Sub Command2_Click()Dim a As Long, q As Longa = Text1.Text Do While (a > 0)q = a Mod 2 & qa = a 2LoopLabel1.Caption = qEnd Sub7.对象对象名称属性属性值说明窗体Form1Caption标签Label1CaptionBorderstyleFontAutosizetrue自动调整大小命令按钮Command1CaptionCommand2Captio

31、nEnableFalse禁用计时器Timer1InternalEnablePrivate Sub Command1_Click()Timer1.Enabled = TrueCommand1.Enabled = FalseCommand1.Caption = "继续"Command2.Enabled = TrueEnd SubPrivate Sub Command2_Click()Command2.Enabled = FalseCommand1.Enabled = TrueTimer1.Enabled = FalseEnd SubPrivate Sub Timer1_Time

32、r()Label1.FontSize = Label1.FontSize * 1.1If Label1.FontSize > 100 ThenLabel1.FontSize = 8End IfEnd Sub实验五 数组1.对象对象名称属性属性值说明窗体Form1Caption文本框Text1TextText2TextLocked命令按钮Command1CaptionCommand2CaptionDim a(1 To 10) As IntegerPrivate Sub Command1_Click()Dim i As IntegerText1.text=""For i

33、= 1 To 10a(i) = Int(Rnd * 81) + 10Text1.Text = Text1.Text & a(i) & Space(2)Next iEnd SubPrivate Sub Command2_Click()Dim i As Integer, j As Integer, t As IntegerText2.text=""For i = 1 To 9For j = i + 1 To 10If a(i) > a(j) Thent = a(j)a(j) = a(i)a(i) = tEnd IfNext jNext iFor i = 1

34、 To 10If a(i) Mod 3 = 0 ThenText2.Text = Text2.Text & a(i) & Space(2)End IfNext iEnd Sub2.对象对象名称属性属性值说明窗体Form1Caption文本框Text2TextText3TextText1Textmultiline水平滚条scrollbars1-horizontal命令按钮Command1CaptionCommand2Caption标签Label1CaptionDim a(1 To 10) As IntegerPrivate Sub Command1_Click()Dim i As

35、 IntegerFor i = 1 To 10a(i) = Int(Rnd * 26) + 65Text1.Text = Text1.Text & a(i) & Space(2)Next iEnd SubPrivate Sub Command2_Click()Dim i As Integer, max As Integermax = a(1)For i = 2 To 10If max < a(i) Thenmax = a(i)End IfNext iText2.Text = maxText3.Text = Chr(max)End Sub3.对象对象名称属性属性值说明窗体F

36、orm1Caption文本框Text2TextText3TextText1Textmultiline水平滚条scrollbars1-horizontal命令按钮Command1CaptionCommand2Caption标签Label1CaptionDim a(1 To 100) As IntegerPrivate Sub Command1_Click()Dim i As IntegerFor i = 1 To 100a(i) = Int(Rnd * 26) + 65Text1.Text = Text1.Text & Chr(a(i) & Space(2)Next iEnd S

37、ubPrivate Sub Command2_Click()Dim i As Integer, b As Integer, j As Integerr = 0b = Asc(Text2.Text)For i = 1 To 100If a(i) = b Thenj = j + 1End IfNext iText3.Text = jEnd Sub4.对象对象名称属性属性值说明窗体Form1Caption文本框Text1Textmultilinescrollbars3-both命令按钮Command1CaptionCommand2Caption标签Label1CaptionBorderstyleDi

38、m a(1 To 5, 1 To 5) As IntegerPrivate Sub Command1_Click()Dim i As Integer, j As IntegerText1.Text = ""For i = 1 To 5For j = 1 To 5a(i, j) = Int(Rnd * 90) + 10Text1.Text = Text1.Text & a(i, j) & Space(2)Next jText1.Text = Text1.Text & vbCrLfNext iEnd SubPrivate Sub Command2_Cli

39、ckDim i as Integer ,j as Integer ,s as Integer For i = 1 to 5 j = 6 is=s+a( i ,j )next iLabel1.caption =sEnd Sub5.对象对象名称属性属性值说明窗体Form1Caption标签Label1Caption文本框Text1TextText2Text命令按钮Command1CaptionDim a() As IntegerPrivate Sub Command1_Click()Dim n As Integer, i As Integeri = Val(Text1.Text)ReDim a(1

40、 To i)a(1) = 1a(2) = 1For n = 3 To ia(n) = a(n - 1) + a(n - 2)Next nText2.Text = a(i)End Sub6.对象对象名称属性属性值说明窗体Form1Caption命令按钮Command1CaptionCommand2Caption文本框Text1TextmultilinescrollbarsText2TextDim a(1 To 50) As IntegerPrivate Sub Command1_Click()Dim i As IntegerText1.text=""For i = 1 To

41、50a(i) = Int(Rnd * 90) + 10Text1.Text = Text1.Text & a(i) & Space(2)Next iEnd SubPrivate Sub Command2_Click()Dim i As IntegerText2.Text = 0For i = 1 To 50If a(i) Mod 3 = 0 And a(i) Mod 7 = 0 ThenText2.Text = Val(Text2.Text) + a(i)End IfNext iEnd Sub7.对象对象名称属性属性值说明窗体Form1Caption文本框Text1Textmu

42、ltilinescrollbars命令按钮Command1CaptionCommand2Caption标签Label1CaptionBorderstyleDim a(1 To 4, 1 To 4) As IntegerPrivate Sub Command1_Click()Dim i As Integer, j As IntegerText1.Text = ""For i = 1 To 4For j = 1 To 4a(i, j) = Int(Rnd * 41) + 10Text1.Text = Text1.Text & a(i, j) & Space(2)

43、Next jText1.Text = Text1.Text & vbCrLfNext iEnd SubPrivate Sub Command2_Click()Dim i As Integer,j as integerFor i=1 to 4t=a(i,1)a(i,1)=a(i,3)a(i,3)=tNext tFor i = 1 To 4 For j = 1 To 4 Label1.Caption = Label1.Caption & a(i, j) & Space(2)Next jLabel1.Caption = Label1.Caption & vbCrLfN

44、ext iEnd Sub实验六 常用控件1.对象对象名称属性属性值说明窗体Form1Caption标签Label1CaptionLabel2CaptionLabel3Caption文本框Text1TextText2TextText3Text框架Frame1Caption单选按钮Op(0)caption加Op(1)captionOp(2)captionOp(3)captionPrivate Sub Op_Click(Index As Integer)Dim a As Integer, b As Integer, c As Integera = Val(Text1.Text)b = Val(Text2.Text)Select Case IndexCase 0 c = a + bCase 1 c = a - bCase 2 c = a * bCase 3 c = a / bEnd SelectText3.Text = Str(c)End Sub2.对象对象名称属性属性值说明窗体Form1Caption列表框List1List2命令按钮Command1CaptionCommand2CaptionDim a(1 To 10)

温馨提示

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

评论

0/150

提交评论