二级计算机VB考试常用代码看完必过_第1页
二级计算机VB考试常用代码看完必过_第2页
二级计算机VB考试常用代码看完必过_第3页
免费预览已结束,剩余23页可下载查看

下载本文档

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

文档简介

1、二级 计 算机 VB 考试代码第一 套1Private Sub Command1_Click()Dim sum As Longn = Val(Text1.Text)sum = 0If n Mod 2 = 0 Then'm = ?Else 'm = ?End If'For i = 1 To m Step ?End Sub'sum = sum + ?NextLabel2.Caption = sumPrivate Function f(ByVal x As Integer) As Longy = 1'For i = 1 To ?y = y * iNext f

2、= y End Function2Option Base 1Private Sub Command1_Click()Dim days%, month%, year%, day1_1%, n%Static month_days As Variant month_days = Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) For k = 0 To 6If Option1(k).Value = True Then day1_1 = kEnd IfNext kdays = 0month = Text2 year = Text1month_d

3、ays(2) = IIf(leap_year(year), 29, ? )'= 计算到要显示月历的月份之前共有多少天 = For k = ? To month - 1days = days + month_days(k) '= 计算要显示月历的月份的第 n = (days Mod 7 + day1_1) Mod 7 '= 输出月 历 Picture1.Cls Picture1.Print " SUNMON TUENext k1 天是星期几WED THU FRISAT"For k = 1 To month_days(month)Picture1.Pri

4、nt Tab(5 * n + 1); k;n = n + 1If n = 7 Then Picture1.Print n = ?End If Next kEnd Sub0)'= 判断闰 年 = 'Private Function leap_year( ? As Integer) As Boolean leap_year = (year Mod 4 = 0 And year Mod 100 <> 0 Or year Mod 400 =End FunctionPrivate Sub Option1_Click(Index As Integer)End Sub3Priva

5、te Type recname As String * 3Math As IntegerChinese As Integer English As Integer End Type Dim a(20) As rec, num As Integer, n As IntegerPrivate Sub readdata()Open App.Path & "in5.txt" For Input As #1k = 1Do While Not EOF(1)Input #1, a(k).name, a(k).Math, a(k).Chinese, a(k).Englishk =

6、k + 1 LoopClose #1'num = ?End SubEnd Subn = n + 1End SubEnd Subputdata nEnd SubPrivate Sub Command1_Click() n = 1 putdata nPrivate Sub Command2_Click()Private Sub Command3_Click() ' n = ? putdata nPrivate Sub Command4_Click() n = numputdata nPrivate Sub Form_Load()Readdata Command1_Click End

7、 Sub 'Private Sub putdata( ? As Integer)Label1.Caption = " 第" & k & " 条记录"Text3 = a(k).ChineseText1 = a(k).name Text2 = a(k).MathText4 = a(k).EnglishText5 = a(k).Math + a(k).Chinese + a(k).English ' SetEnabled ?End SubPrivate Sub SetEnabled(m As Integer) Command1.

8、Enabled = IIf(m = 1, False, True) Command2.Enabled = IIf(m = num, False, True) Command3.Enabled = IIf(m = 1, False, True)' Command4.Enabled = IIf( ? ) End Sub 第二 套Private Sub Form_Load() Command1.Caption = " 开始 " Timer1.Interval = 100End SubCommand2.Caption = " 停止 "Timer1.Ena

9、bled = FalsePrivate Sub Command1_Click() 'Command1.Caption = ? 'Command1.Enabled = ?End SubPrivate Sub Command2_Click() Timer1.Enabled = False 'Command1.Enabled = ?End SubTimer1.Enabled = TrueCommand2.Enabled = TrueCommand2.Enabled = FalsePrivate Sub Timer1_Timer()If HScroll1.Value <

10、HScroll1.Max Then 'HScroll1.Value = ?Else 'HScroll1.Value = ?End IfEnd Sub2Private Sub Command1_Click()'st1 = Trim( ? )n = 1st2 = UCase(Left(st1, 1)Do While n <= Len(st1)If Mid(st1, n, 1) <> " " Then'st2 = ? & Mid(st1, n + 1, 1)n = n + 1End IfIf Mid(st1, n, 1)

11、= " " Thenst2 = st2 & UCase(Mid(st1, n + 1, 1) n = n + 1End IfLoop'Text2.Text = ? End SubFunction prime(ByVal n As Integer) As Boolean> *考生编写 *> *End FunctionPrivate Sub Form_Click()> *考生编写 *> *Open App.Path & "out5.txt" For Output As #1Print #1, Text1.Tex

12、tClose 1End Sub 第三 套 1 Private Sub Dir1_Change() ' = ?End SubPrivate Sub Drive1_Change() ' Dir1.Path = ?End SubPrivate Sub () Label2.Caption =End SubPrivate Sub Option1_Click(Index As Integer) ' If ? = 0 ThenDrive1.Drive = "c:"一叶*nElse' = ?End IfEnd Sub2Dim a(5, 5) As Strin

13、gPrivate Sub Command1_Click()Dim s As StringRandomizeFor i = 1 To 5For j = 1 To 5a(i, j) = Chr(Rnd * (90 - 65) + 65)iiNext s = s & Chr(13) & Chr(10)Next' Text1 = ?End SubPrivate Sub Command2_Click()MaxI = 1MaxJ = 1Max = Asc(a(1, 1)For i = 1 To 5For j = 1 To 5' If ? > Max ThenMax =

14、 Asc(a(i, j)MaxI = iMaxJ = jEnd IfNextNext' Text2 = Chr( ? ) & Str(MaxI) & Str(MaxJ)End Sub3Dim a(5, 5) As LongDim b(5, 5) As LongPrivate Sub Command1_Click()'Open App.Path & "in5.txt" For? As #1For i = 1 To 5For j = 1 To 5'Input #1, ?s = s + Str(a(i, j)Nexts = s +

15、Chr(13) + Chr(10)NextText1 = s' ?End SubPrivate Sub Command2_Click()'= 以下由考生编写 = '= 考生 编写程序结束 = End SubPrivate Sub Command3_Click()'= 以 下由 考生 编写 ='= 考 生编写程序结束 = Open App.Path & "out5.txt" For Output As #1 Print #1, Label2.CaptionClose #1End Sub 第四 套 1 Private Sub Co

16、mmand1_Click()RandomizeText2.Locked = FalseText1 = "": Text2 = "": text3 = ""For i = 1 To 20 s = Chr$(Int(Rnd * 26) + 97) 'Text1 = Text1 + ?NextEnd SubPrivate Sub Text2_KeyPress(KeyAscii As Integer)Dim m As Integer, n As IntegerIf Len(Text2) = 20 Then ' Text2.Lo

17、cked = ?m = 0: n = 0 For i = 1 To 20'If Mid(Text2, i, 1) = ? Then'm = ?Else'n = ?End If Nexttext3 = m / (m + n) * 100 & "%" End IfEnd SubPrivate Sub Command2_Click()EndEnd Sub2Option Base 1Dim stu(1 To 50) As StudTypeDim n%Private Sub Cmd1_Click(Index As Integer)' Selec

18、t Case ?Case 0If n < 50 Then' n = ?人"stu(n).Num = Text1 stu(n).Name = Text2 stu(n).Total = Text3 Text1 = "": Text2 = "": Text3 = ""Label4.Caption = " 已输入 " & Space(1) & n & Space(1) & " ElseMsgBox " 输入人数已超过 50!"End If

19、Case 1'Max = ?maxi = 1For j = 2 To n' If stu(j).Total > ? ThenMax = stu(j).Total'maxi = ?End IfNextText1 = stu(maxi).NumText2 = stu(maxi).NameText3 = stu(maxi).TotalLabel4.Caption = " 位置: " & Space(2) & maxi & "/" & n Case 2EndEnd SelectEnd SubOptio

20、n Base 1Dim a(20, 6) As IntegerPrivate Sub Command1_Click()Open App.Path & "in5.dat" For Input As #1 For i = 1 To 20For j = 1 To 6 Input #1, a(i, j)Text1 = Text1 + Str(a(i, j) + Space(1) Next jText1 = Text1 + Chr(13) + Chr(10)Next iClose #1End SubPrivate Sub Command2_Click()'= 以下由考

21、生编写 = '= 考生编写程序结束 = End SubPrivate Sub Form_Unload(Cancel As Integer)Open App.Path & "out5.dat" For Output As #1Print #1, Text2.TextClose #1End Sub 第五 套1Private Sub Command1_Click()Randomize'For k = ? To 9'? = Int(Rnd * 90 + 10)Next kEnd SubPrivate Sub Command2_Click()'

22、For k = 0 To ?temp = Label1(k).CaptionLabel1(k).Caption = Label1(9 - k).Caption'? = tempNext kEnd Sub2Dim r%, x0%, y0, aPrivate Sub Command1_Click()Timer1.Enabled = TrueEnd SubPrivate Sub Form_Load()r = Shape1.Width / 2' x0 = ? + ry0 = Shape1.Top + r'Image1.Left = x0 - ?Image1.Top = y0 -

23、 r - Image1.Height / 2 a = 90End SubPrivate Sub Timer1_Timer()Dim x, ya = a - 3x = x0 + r * Cos(a * 3.14159 / 180)y = y0 - r * Sin(a * 3.14159 / 180)'Image1.Left = ? - Image1.Width / 2'Image1.Top = ? - Image1.Height / 2End Sub3Private Sub Command1_Click() Open "in5.dat" For Input A

24、s #1 n = LOF(1)'ch$ = Input(n, ? )Close #1Text1.Text = chEnd SubPrivate Sub Command2_Click() Dim IsSpace As Boolean ch1$ = Text1.Text' n = Len( ? ) IsSpace = True For k = 1 To n'双引号中是一个空格符' c = Mid(ch1, k, ? )If c = " " Then IsSpace = TrueElseIf IsSpace Then c = UCase(c) Is

25、Space = FalseEnd IfEnd If' ch2$ = ch2$ & ?Next kText1.Text = ch2End SubPrivate Sub Command3_Click()Open "out5.dat" For Output As #1Print #1, Text1.TextClose #1End Sub第六 套1Private Sub Command1_Click()str1 = Text1.Textstr2 = Text2.Text'n = Len(?)'For i = 1 To Len(?)If Mid(str

26、1, i, n) = RTrim(str2) Then'MsgBox str2 & " 的起始位置是: " & ?Exit ForEnd IfNext' If i > ? Then MsgBox " 没有找到 !"End SubPrivate Sub Form_Load()Text1.Text = "Last week I went to the theatre. I had a good seat. The play is very interesting. I did not enjoy it. A y

27、oung man and a young woman were seating behind me. They were talking loudly."End Sub2Private Sub showPic_Click()Picture1.Visible = TrueText1.Visible = False'If ? = " 显示图片 " ThenPicture1.Picture = LoadPicture(App.Path & "pic4.bmp") showPic.Caption = " 清空图片 "

28、Else'Picture1.Picture = ?showPic.Caption = " 显示图片 "End IfEnd SubPrivate Sub showText_Click()' Picture1.Visible = ?Text1.Visible = True'Open App.Path & "data4.dat" ? As #1Input #1, s ' Text1.Text = ?Close #1 End Sub 3 Private Sub Command1_Click()Open App.Path &

29、amp; "data5.dat" For Input As #1Input #1, x ' Label1.Caption = ? ' Close ? End SubPrivate Sub Command2_Click()'= 以 下考 生编 写 = '= 考 生编 写程 序结 束 =Open App.Path & "out5.dat" For Output As #1Print #1, Label2.CaptionClose #1 End SubPrivate Function p(n As Integer) As

30、 Booleanflag = TrueFor i = 2 To Sqr(n) If n Mod i = 0 Then flag = False Exit For End IfNext i p = flag End Function 第七 套 1 Private Sub Command1_Click()For i = 0 To 6 ' k = ? 'For j = i + 1 To ?' If Val(Text1(j).Text) > ? Then k = jEnd If Next j j = Text1(i).Text Text1(i).Text = Text1(

31、k).Text'Text1(k).Text = ?Next i End Sub 2 Private Sub Command1_Click()For k = 0 To Combo1.ListCount - 1 'If Combo1.Text = ? ThenExit For End IfNext kIf k >= Combo1.ListCount Then ' Combo1.AddItem ?Else MsgBox (" 此项目已存在! ")End If End SubPrivate Sub Command2_Click()If Combo1.L

32、istIndex >= 0 Then 'Combo1.RemoveItem ?End If End SubPrivate Sub Command3_Click() 'Text1.Text = Text1.Text & " " & ?End SubPrivate Sub Command4_Click() '? = ""End Sub3 Option Base 1 Dim s As StringPrivate Sub Command1_Click()Open App.Path & "in5.da

33、t" For Input As #1 s = Input(LOF(1), #1)Close #1Text1.Text = s End SubPrivate Function GetWords(s As String, words() As String) As IntegerDim m%, ch$ch = ""For k = 1 To Len(s)c = Mid(s, k, 1)If c <> " " Thench = ch + cElsem = m + 1words(m) = ch ch = ""End IfN

34、ext k'GetWords = ?End FunctionPrivate Sub Command2_Click()Dim ch(800) As String, n As IntegerIf Len(s) = 0 ThenMsgBox " 请先使用“读数据”功能!"Else'm = GetWords( ? , ch )' 考生编写的程序代码从这里开始' 考生编写的程序代码到这里结束End IfEnd SubPrivate Sub Form_Unload(Cancel As Integer)Open App.Path & "o

35、ut5.dat" For Output As #1 Print #1, Label1.CaptionClose #1End Sub第八 套Private Sub Command1_Click()Dim s As LongDim i As Integeri = 0: s = 0'While i <?' ?s = s + jc(i)WendText1.Text = sEnd SubFunction jc(n As Integer) As LongDim i As IntegerDim t As Long' ?'For i = 1 To ?t = t

36、* iNext' ?End Function2Option Base 1Private Sub Command1_Click()Dim arr(50) As IntegerDim i As Integer, j As IntegerDim x As Integer, max As Integer, pos As IntegerRandomizemax = 0: pos = 1i = 1Dox = Int(Rnd * 101)' ?Do While j < iIf x <> arr(j) Then'j = j + ?ElseExit DoEnd IfLo

37、opIf j = i Then'arr(j) = ?Print arr(j);i = i + 1If (i - 1) Mod 10 = 0 Then PrintIf max < x Thenmax = x ' pos = ? End IfEnd IfLoop Until i > 50Text1.Text = maxText2.Text = posEnd Sub3Dim a(100) As IntegerPrivate Sub Command1_Click()Dim k As IntegerOpen App.Path & "in5.dat"

38、 For Input As #1For k = 1 To 100Input #1, a(k)Next kClose #1End SubPrivate Sub Command2_Click()Dim i As Integer, j As IntegerDim b(100) As Integerj = 0For i = 1 To 100If prime(a(i) Thenj = j + 1b(j) = a(i)End IfNextFor i = 1 To jText1 = Text1 + Str(b(i)NextEnd Sub'以 下 Function 过程用于判断某数是否为质数 Func

39、tion prime(p As Integer) As Boolean'考生编写End FunctionPrivate Sub Form_Unload(Cancel As Integer)Open App.Path & "out5.dat" For Output As #1 Print #1, Text1.TextClose #1End Sub 第九 套Dim n As IntegerPrivate Sub Form_Click() ' Timer1.Enabled = ? End SubPrivate Sub Form_Load()' Ti

40、mer1.Interval = ?Timer1.Enabled = FalseText1.ForeColor = 0n = 0End SubPrivate Sub Timer1_Timer()'n = ?If n Mod 5 = 0 Then Text1.Text = Time()End IfIf n Mod 8 = 0 Then'If Text1.ForeColor = ? ThenText1.ForeColor = &HFFElseText1.ForeColor = 0End IfEnd IfEnd Sub2Dim a%(1 To 10)Private Sub Co

41、mmand1_Click()RandomizeFor k = 1 To 10 a(k) = Int(Rnd * 90 + 10) Picture1.Print a(k);Next kPicture1.PrintPicture1.Print "End SubPrivate Sub Command2_Click() m% = Val(Text1)' MoveArray a(), ?For k = 1 To 10Picture1.Print a(k);Next kPicture1.PrintEnd SubSub MoveArray(a() As Integer, m As Inte

42、ger) n% = UBound(a)' For k = 1 To ?x = a(1) For j = 1 To n - 1'a(j) = a( ? )Next j'a(n) = ?Next kEnd Sub3Private Type rec name As String * 3 Math As Integer Chinese As Integer English As IntegerEnd TypeDim a(30) As rec, num As IntegerPrivate Sub Command1_Click()Open App.Path & "

43、in5.txt" For Input As #1 k = 1'Do While Not EOF( ? )Input #1, a(k).name, a(k).Math, a(k).Chinese, a(k).English k = k + 1Loop Close #1 ' num = ? End SubPrivate Sub Command2_Click()'=考 生编写 =End SubPrivate Sub Command3_Click()Open App.Path & "out5.dat" For Output As #1For

44、 k = 1 To numPrint #1, a(k).nameNext kClose #1End SubPrivate Function sum(k As Integer) As Integer sum = a(k).Math + a(k).Chinese + a(k).EnglishEnd Function第十 套Private Sub Command1_Click()' If ? Or = - 1 Then= 0ElseIf >= 0 Then' = ?End IfEnd IfShowInforEnd SubPrivate Sub ()Call ShowInforE

45、nd SubPrivate Sub ShowInfor()' Label1.Caption = App.Path + "" + ?Image1.Picture = LoadPicture(Label1.Caption)End SubPrivate Sub Form_Load()= App.Path' File1. ?End Sub2Private Sub Command1_Click()Dim fstr As String, ostr As StringDim times As Integer, pos As IntegerDim ans As Intege

46、rfstr = InputBox(" 输入待查内容 ", " 查找 ") If fstr = "" ThenExit SubEnd Iftimes = 0ostr = Text1.Textpos = InStr(1, ostr, fstr)Do While pos <> 0' Text1.SelStart = ?' Text1.SelLength = ?' times = ? Text2.Text = timesans = MsgBox(" 找到了,是否继续查找?", vbYes

47、No)If ans = vbYes Thenpos = pos + Len(fstr) ' pos = ? ElseExit DoEnd IfLoopEnd Sub3Option ExplicitOption Base 1Dim a(10) As IntegerPrivate Sub Command1_Click()Dim i As IntegerList1.ClearOpen App.Path & "in5.dat" For Input As #1For i = 1 To 10Input #1, a(i)List1.AddItem (a(i)Next iC

48、lose #1End Sub强化 31Private Sub Command2_Click()'= 考生编写的程序 =IEnd SubPrivate Sub Command3_Click()Dim i As IntegerOpen App.Path & "out5.dat" For Output As #1For i = 0 To 9Print #1, List2.List(i)Next iClose #1 End Sub Private Sub C1_Click()Dim k As Integer 'Form2. ?Form2.Print Form

49、1.L1.Caption; Form1.Text1Form2.Print Form1.L2.Caption; Form1.Text2Form2.Print Form1.L3.Caption; Form1.Text3 'Form2.Print Form1.Frame1. ? ; " : "For k = 0 To 1' If Form1.Op1( ? ).Value Then Form2.Print Form1.Op1(k).CaptionEnd IfNext k End SubPrivate Sub Form_Load() ' Text2. ? =

50、"*" End Sub 2Private Sub C1_Click() ' If ? = "123456" ThenText1.Text = " 口令 正 确 "' Text1.? = ""ElseText2.Text = Text2.Text - 1 ' If Text2.Text > ? Then输入MsgBox " 第 " & (3 - Text2.Text) & " 次口令错误,请重新IIElseMsgBox "3 次输入

51、错误,请退出 "' Text1.Enabled = ?End IfEnd IfEnd Sub 强化 32 Private Sub Form_load()HScroll1.Min = Shape2.Left ' HScroll1.Max = Shape2.Width + Shape2.Left - Shape1. ?VScroll1.Min = Shape2.Top' VScroll1.Max = Shape2.Height + ? - Shape1.HeightHScroll1.Value = 1000VScroll1.Value = 1000 End Sub

52、Private Sub HScroll1_Change()' ? = HScroll1.Value End SubPrivate Sub VScroll1_Change()'Shape1.Top = ?End Sub2Dim a, t, dPrivate Sub Command1_Click()' Timer1.? = Trued = Image1.Top End SubPrivate Sub Command2_Click()Open App.Path & "out4.txt" For Output As #1Print #1, Label1

53、, Label2Close #1 End SubPrivate Sub Form_Load()a = 1t = 0 End SubPrivate Sub Timer1_Timer()Image1.Top = Image1.Top - a * 50If Image1.Top + Image1.Height <= Image2.Top + Image2.Height - 200 Then'? = False'd = ? - Image1.TopLabel1 = d Label2 = t * Timer1.Interval / 1000End Ifa = a + 0.1 

54、9;t = ?End Sub3Dim a(30) As Integer, b(30) As Integer, c(60) As IntegerPrivate Sub Command1_Click()Dim k As IntegerOpen App.Path & "in5.dat" For Input As #1For k = 1 To 30Input #1, a(k)Text1 = Text1 + Str(a(k) + Space(2)Next kFor k = 1 To 30Input #1, b(k)Text2 = Text2 + Str(b(k) + Spac

55、e(2)Next kClose #1End Sub'考 生编写程 序Private Sub Command2_Click()For k = 1 To 60 Text3 = Text3 + Str(c(k) + Space(2)Next kEnd SubPrivate Sub Form_Unload(Cancel As Integer)Open App.Path & "out5.dat" For Output As #1Print #1, Text3.TextClose #1End Sub 强化 33Private Sub Command1_Click()Di

56、m n As IntegerCls' ? = InputBox(" 请输入一个整数 ")Print " 因子数 =" fun(n)End SubFunction fun(m As Integer)Dim s As Integers = 0For k = 1 To Abs(m) / 2 'If m Mod k = ? Thens = s + 1 Print kEnd IfNext k' ?End Function2Private Sub Command1_Click()Dim k%'For k = List1.ListCou

57、nt - 1 To 0 ?If List1.Selected(k) = True Then 'List2.AddItem ?'List1.RemoveItem ?End IfNext kEnd SubPrivate Sub Command2_Click()Dim k%Text1 = " 已经选中的城市有: "For k = 0 To List2.ListCount - 1 Step 1 'Text1 = ? & " " & List2.List(k)Next kEnd Sub3Dim stepy As Intege

58、r' 纵向移动增量Dim stepx As Integer' 横向移动增量Const LEFT_BUTTON = 1Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x AsSingle, y As Single)'圆的半径'圆 心的 x 坐标' 圆心的 y 坐 标Dim x0 As Integer, y0 As Integer, a As Single, radius As Integerradius = Shape1.Width / 2If Button = LEFT_BUTTON Then x0 = Shape1.Left + radius y0 = Shape1.Top + radius If x = x0 Thenstepy = Sgn(y - y0) * 50 stepx = ?Elsea = (

温馨提示

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

评论

0/150

提交评论