二级计算机VB考试常用代码(看完必过)_第1页
二级计算机VB考试常用代码(看完必过)_第2页
二级计算机VB考试常用代码(看完必过)_第3页
二级计算机VB考试常用代码(看完必过)_第4页
二级计算机VB考试常用代码(看完必过)_第5页
已阅读5页,还剩21页未读 继续免费阅读

下载本文档

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

文档简介

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 ?'sum = sum + ? Next Label2.Caption = sum End SubPrivate Function f(ByVal x As Integer) As Longy = 1' For i = 1 To ?y = y * i N

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

3、#39; month_days(2) = IIf(leap_year(year), 29, ? )'= 计算到要显示月历的月份之前共有多少天=' For k = ? To month - 1Next k1 天是星期几=WED THU FRI SAT"n = n + 1days = days + month_days(k)'= 计算要显示月历的月份的第n = (days Mod 7 + day1_1) Mod 7'= 输出月 历Picture1.ClsPicture1.Print " SUN MON TUEFor k = 1 To month_

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

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

6、shk = k + 1 Loop Close #1' num = ?End SubPrivate Sub Command1_Click()n = 1 putdata n End Subputdata n End SubPrivate Sub Command2_Click()n = n + 1Private Sub Command3_Click()n = ? putdata n End SubPrivate Sub Command4_Click()n = num putdata n End SubPrivate Sub Form_Load()Readdata Command1Click

7、End SubPrivate 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).EnglishSetEnabled ?End SubPrivate Sub SetEnabled(m As Integer)Command1.Enabled

8、 = IIf(m = 1, False, True)Command2.Enabled = IIf(m = num, False, True)Command3.Enabled = IIf(m = 1, False, True)' Command4.Enabled = IIf( ? )End Sub1Command2.Caption = " 停 止 "Timer1.Enabled = FalsePrivate Sub Form_Load()Command1.Caption = " 开 始 "Timer1.Interval = 100End SubPr

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

10、hen'HScroll1.Value = ?Else'HScroll1.Value = ?End IfEnd Sub2Private Sub Command1_Click()'st1 = Trim( ? )n = 1 st2 = 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 Sub3Function prime(ByVal n As Integer) As Boolean' * 考生编写*' *End FunctionPrivate Sub Form_Click()' * 考生编写*' *Open App.Path & "out5.txt" For Output As #1Print #1, Text1.TextClose 1End

12、Sub第三 套1Private Sub Dir1_Change()' File1.Path = ?End SubPrivate Sub Drive1_Change()' Dir1.Path = ?End SubPrivate Sub File1_Click()Label2.Caption = File1.FileNameEnd SubPrivate Sub Option1_Click(Index As Integer)' If ?= 0 ThenDrive1.Drive = "c:"File1.Pattern = "*.*"Els

13、e'File1.Pattern = ?End IfEnd Sub2Dim a(5, 5) As StringPrivate Sub Command1_Click()Dim s As StringRandomizeFor i = 1 To 5For j = 1 To 5a(i, j) = Chr(Rnd * (90 - 65) + 65)'s = s + ? + ""Nexts = s & Chr(13) & Chr(10)Next' Textl = ?End SubPrivate Sub Command2_Click()MaxI =

14、1MaxJ = 1Max = Asc(a(1, 1)For i = 1 To 5Forj = 1 To 5'If ? > Max ThenMax = Asc(a(i, j)MaxI = i MaxJ = j End 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" Fo

15、r ? As #1For i = 1 To 5Forj = 1 To 5'Input #1, ?s = s + Str(a(i, j)Nexts = s + Chr(13) + Chr(10) Next Text1 = s'?End SubPrivate Sub Command2_Click()=以下由考生编写= '=考生编写程序结束= End SubPrivate Sub Command3_Click()'=以下由考生编写= 考 生编写程序结束=Open App.Path & "out5.txt" For Output As #1P

16、rint #1, Label2.CaptionClose #1End Sub第四 套1Private Sub Command1_Click()RandomizeText2.Locked = FalseText1 = "": Text2 = "": text3 = ""For i = 1 To 20s = Chr$(Int(Rnd * 26) + 97) 'Text1 = Text1 + ?NextEnd SubPrivate Sub Text2_KeyPress(KeyAscii As Integer) Dim m As In

17、teger, n As IntegerIf Len(Text2) = 20 Then ' Text2.Locked = ?m = 0: n = 0For i = 1 To 20' If Mid(Text2, i, 1) = ? Then'm = ?Else'n = ?End IfNexttext3 = m / (m + n) * 100 & "%"End IfEnd SubPrivate Sub Command2_Click()EndEnd Sub2Option Base 1Dim stu(1 To 50) As StudTypeDi

18、m n%Private Sub Cmd1_Click(Index As Integer) ' Select Case ?Case 0If n < 50 Thenstu(n).Num = Text1stu(n).Name = Text2stu(n).Total = Text3Text1 = "": Text2 = "": Text3 = ""Label4.Caption = " 已输入 " & Space(1) & n & Space(1) & " 人ElseM

19、sgBox " 输入人数已超过50!"End IfCase 1Max = ?maxi = 1For j = 2 To nIf stu(j).Total > ? Then Max = stu(j).Total maxi = ?End IfNextText1 = stu(maxi).NumText2 = stu(maxi).NameText3 = stu(maxi).TotalLabel4.Caption = " 位置: " & Space(2) & maxi & "/" & nCase 2EndEn

20、d SelectEnd SubOption Base 1Dim a(20, 6) As IntegerPrivate Sub Command1_Click()Open App.Path & "in5.dat" For Input As #1For i = 1 To 20For j = 1 To 6Input #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_C

21、lick()=以下由考生编写= =考生编写程序结束= 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、39; 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

23、= y0 - 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 In

24、put As #1n = LOF(1)' ch$ = Input(n, ? )Close #1Text1.Text = chEnd SubPrivate Sub Command2_Click()Dim IsSpace As Boolean ch1$ = Text1.Text' n = Len( ? )IsSpace = TrueFor 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 youn

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

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

29、quot;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 #1End SubPrivate Function p(n As Integer) As Booleanflag = TrueFor

30、 i = 2 To Sqr(n)If n Mod i = 0 Thenflag = FalseExit ForEnd IfNext ip = flagEnd Function第七套1Private Sub Command1_Click() Fori = 0 To 6'k = ?'For j = i + 1 To ?'If Val(Text1(j).Text) > ? Thenk = jEnd IfNext jj = Text1(i).TextText1(i).Text = Text1(k).TextText1(k).Text = ?Next iEnd Sub2Pr

31、ivate Sub Command1_Click()For k = 0 To Combo1.ListCount - 1'If Combo1.Text = ? ThenExit ForEnd IfNext kIf k >= Combo1.ListCount Then'Combo1.AddItem ?ElseMsgBox (" 此项目已存在!")End IfEnd SubPrivate Sub Command2_Click()If Combo1.ListIndex >= 0 Then'Combo1.RemoveItem ?End IfEnd

32、SubPrivate Sub Command3_Click()' Text1.Text = Text1.Text & " " & ?End SubPrivate Sub Command4_Click()'? = ""End Sub3Option Base 1Dim s As StringPrivate Sub Command1_Click()Open App.Path & "in5.dat" For Input As #1s = Input(LOF(1), #1)Close #1Text1.Te

33、xt = sEnd 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) = chch = ""End IfNext k' GetWords = ?End FunctionPrivate Sub Command2_Click()

34、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 & "out5.dat" For Output As #1Print #1, Label1.CaptionClose #

35、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 * iNext'?End Function2Option Base 1Private Sub Command1_Cli

36、ck()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 IfLoopIf j = i Then'arr(j) = ?Print arr(j);i = i + 1If (i - 1) Mo

37、d 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" For Input As #1For k = 1 To 100Input #1, a(k)Next kClose #1End Sub

38、Private 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 过程用于判断某数是否为质数Function prime(p As Integer) As Boolean'考生编写End FunctionPrivate Sub

39、Form_Unload(Cancel As Integer)Open App.Path & "out5.dat" For Output As #1Print #1, Text1.TextClose #1End Sub第九 套Dim n As IntegerPrivate Sub Form_Click()' Timer1.Enabled = ?End SubPrivate Sub Form_Load()' Timer1.Interval = ?Timer1.Enabled = FalseText1.ForeColor = 0n = 0End SubPr

40、ivate Sub Timer1_Timer()' n = ?If n Mod 5 = 0 ThenText1.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 Command1_Click()RandomizeFor k = 1 To 10a(k) = Int(Rnd * 90 + 10)Picture1.

41、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 kPicturel.PrintEnd SubSub MoveArray(a() As Integer, m As Integer) n% = UBound(a)' For k = 1 To ?x = a(1)For j = 1 To n - 1 'a(j)

42、 = a( ?)Next j 'a(n) = ?Next kEnd Sub3Private Type recname As String * 3Math As IntegerChinese As IntegerEnglish As IntegerEnd TypeDim a(30) As rec, num As IntegerPrivate Sub Command1_Click()Open App.Path & "in5.txt" For Input As #1 k = 1' Do While Not EOF( ?)Input #1, a(k).nam

43、e, a(k).Math, a(k).Chinese, a(k).English k = k + 1LoopClose #1 ' num = ? End SubPrivate Sub Command2_Click()= 考生编写='=End SubPrivate Sub Command3_Click()Open App.Path & "out5.dat" For Output As #1For k = 1 To numPrint #1, a(k).nameNext kClose #1End SubPrivate Function sum(k As I

44、nteger) As Integersum = a(k).Math + a(k).Chinese + a(k).EnglishEnd Function第十 套Private Sub Command1_Click()' If ? Or File1.ListIndex = File1.ListCount - 1 ThenFile1.ListIndex = 0ElseIf File1.ListIndex >= 0 Then'File1.ListIndex =?End IfEnd IfShowInforEnd SubPrivate Sub File1_DblClick()Call

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

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

47、找?", vbYesNo)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

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

49、int Form1.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 ThenForm2.Print Form1.Op1(k).CaptionEnd IfNext kEnd SubPrivate Sub Form_Load()' Text2.

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

51、输入错误,请退出"'Text1.Enabled = ?End IfEnd IfEnd Sub强化 32Private 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 = 1000End SubPriv

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

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

54、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) + Space(

55、2)Next kClose #1End Sub'考 生编写程序Private Sub Command2_Click()For k = 1 To 60Text3 = 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()Dim n A

56、s 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 + 1Print kEnd IfNext k'?End Function2Private Sub Command1_Click()Dim k%' For k = List1.ListCount - 1 T

57、o 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 Integer'纵向移动增量Dim stepx As Integer'横向移动增量Const LEFT_BUTTON = 1Private Sub Form_MouseDown(

温馨提示

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

评论

0/150

提交评论