二级计算机VB考试常用代码_第1页
二级计算机VB考试常用代码_第2页
二级计算机VB考试常用代码_第3页
二级计算机VB考试常用代码_第4页
二级计算机VB考试常用代码_第5页
已阅读5页,还剩23页未读 继续免费阅读

下载本文档

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

文档简介

1、二级计算机VB考试代码第一套1Private Sub Comma nd1_Click()Dim sum As Longn = Val(Text1.Text)sum = 0 If n Mod 2 = 0 The nm = ?Elsem = ?End If For i = 1 To m Step ?End Subsum = sum + ? NextLabel2.Capti on = sumPrivate Fun cti on f(ByVal x As In teger) As Longy = 1 Fori = 1 To?y = y * iNext f = yEnd Fun cti on2Optio

2、n Base 1Private Sub Comma nd1_Click()Dim days%, mon th%, year%, day1_1%, n%Static mon th_days As Varia ntmon th_days = Array(31,28, 31,30, 31,30, 31,31,30, 31, 30, 31) For k = 0 To 6If Optio n1(k).Value = True The nday1_1 = kEnd IfNext k days = 0 month = Text2 year = Text1mon th_days(2) = IIf(leap_y

3、ear(year), 29, ?)=计算到要显示月历的月份之前共有多少天=For k = ? To mon th - 1days = days + mon th_days(k) = 计算要显示月历的月份的第 n = (days Mod 7 + day1_1) Mod 7 = 输出月历 Picture1.ClsPicture1.Pri nt SUNMON TUENext k1天是星期几WED THU FRISATFor k = 1 To mon th_days(m on th)Picture1.Pri nt Tab(5 * n + 1); k;n = n + 1If n = 7 The nPic

4、ture1.Pri ntn = ?End If Next kEnd Sub= 判断闰年=Private Function leap_year( ? As In teger) As Boolea n0)leap_year = (year Mod 4 = 0 And year Mod 100 0 Or year Mod 400 =End Fun cti onPrivate Sub Optio n1_Click(l ndex As In teger)End Sub3Private Type recn ame As Stri ng * 3Math As In tegerChin ese As In t

5、egerEn glish As In tegerEnd TypeDim a(20) As rec, num As In teger, n As In tegerPrivate Sub readdata()Ope n App.Path & in 5.txt For In put As #1k = 1 Do While Not EOF(1)In put #1, a(k) .n ame, a(k).Math, a(k).Chi nese, a(k).E nglish k = k + 1Loop Close #1 num = ?End SubPrivate Sub Comma nd1_Click()n

6、 = 1 putdata nEnd SubPrivate Sub Comma nd2_Click()n = n + 1 putdata n End SubPrivate Sub Comma nd3_Click() n = ? putdata nEnd SubPrivate Sub Comma nd4_Click()n = num putdata n End SubPrivate Sub Form_Load()ReaddataComma nd1_ClickEnd Sub卩 rivate Sub putdata( ? As In teger)Label1.C apti on = 第& k & 条记

7、录Text1 = a(k). nameText2 = a(k).MathText3 = a(k).Chi neseText4 = a(k).E nglishText5 = a(k).Math + a(k).Chi nese + a(k).E nglishSetE nabled ?End SubPrivate Sub SetE nabled(m As In teger)Comma nd1.E nabled = IIf(m = 1, False, True)Command2.Enabled = IIf(m = num, False, True)Comma nd3.E nabled = IIf(m

8、= 1, False, True) Comma nd4.E nabled = IIf( ? )End Sub第二套1Private Sub Form_Load()Comma ndl.C aptio n = 开始Timerl.l nterval = 100Comma nd2.Captio n = 停止Timer1.E nabled = FalseEnd SubPrivate Sub Comma nd1_Click() Comma nd1.Captio n = ? Comma ndl.E nabled = ?End SubTimerl.E nabled = TrueComma nd2.E nabl

9、ed = TrueComma nd2.E nabled = FalsePrivate Sub Comma nd2_Click() Timerl.E nabled = False Comma ndl.E nabled = ?End SubPrivate Sub Timer1_Timer()If HScrolll.Value HScrolll.Max ThenHScrolll.Value = ?ElseHScrolll.Value = ?End IfEnd Sub2Private Sub Comma nd1_Click()st1 = Trim( ?)n = 1 st2 = UCase(Left(s

10、t1, 1)Do While n = Len (stl)If Mid(st1, n, 1) Thenst2 = ? & Mid(st1, n + 1,1)n = n + 1End IfIf Mid(st1, n, 1) = The nst2 = st2 & UCase(Mid(st1, n + 1, 1)n = n + 1End IfLoopText2.Text = ?End SubFun cti on prime(ByVal n As In teger) As Boolea n *考生编写* *End Fun cti onPrivate Sub Form_Click() *考生编写* *Op

11、en App.Path & out5.txt For Output As #1Print #1, Text1.TextClose 1End Sub第三套1Private Sub Dir1_Cha nge() File1.Path = ?End SubPrivate Sub Drive1_Cha nge() Dir1.Path = ?End SubPrivate Sub File1_Click()Label2.C aptio n = File1.FileNameEnd SubPrivate Sub Optio n1_Click(l ndex As In teger) If ?= 0 The nD

12、rive1.Drive = c:File1.Pattern = *.*ElseFile1.Pattern = ?End IfEnd Sub2Dim a(5, 5) As Stri ngPrivate Sub Comma nd1_Click()Dim s As Stri ngRan domizeFor i = 1 To 5Forj = 1 To 5a(i, j) = Chr(R nd * (90 - 65) + 65)IINexts = s & Chr(13) & Chr(10)NextTextl = ?End SubPrivate Sub Comma nd2_Click()Maxi = 1Ma

13、xJ = 1Max = Asc(a(1, 1)For i = 1 To 5Forj = 1 To 5If ? Max The nMax = 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 Comma nd1_Click()Ope n App.Path & in 5.txt For ? As #1For i = 1 To 5Forj = 1 To 5 in put #1

14、, ?s = s + Str(a(i, j)Nexts = s + Chr(13) + Chr(10)NextText1 = s ?End SubPrivate Sub Comma nd2_Click()= 以下由考生编写=考生编写程序结束= End SubPrivate Sub Comma nd3_Click()= 以下由 考生 编写=考生编写程序结束 =Open App.Path & out5.txt For Output As #1Print #1, Label2.C apti onClose #1End Sub第四套1Private Sub Comma nd1_Click()Ran d

15、omizeText2.Locked = FalseText1 = : Text2 = : text3 =For i = 1 To 20s = Chr$(Int(Rnd * 26) + 97) Text1 = Text1 + ?NextEnd SubPrivate Sub Text2_KeyPress(KeyAscii As In teger)Dim m As In teger, n As In tegerIf Le n(Text2) = 20 The nText2 丄 ocked = ?m = 0: n = 0For i = 1 To 20 If Mid(Text2, i, 1) = ? Th

16、e nm = ?Elsen = ?End IfNexttext3 = m / (m + n) * 100 & %End IfEnd SubPrivate Sub Comma nd2_Click()EndEnd Sub2Option Base 1Dim stu(1 To 50) As StudTypeDim n%Private Sub Cmd1_Click(l ndex As In teger) Select Case ?Case 0If n ? The nMax = stu(j).Totalmaxi = ?End IfNextTextl = stu(maxi).NumText2 = stu(m

17、axi).NameText3 = stu(maxi).TotalLabel4.C apti on = 位置:& Space(2) & maxi & / & n Case 2EndEnd SelectEnd SubOption Base 1Dim a(20, 6) As In tegerPrivate Sub Comma nd1_Click()Open App.Path & in5.dat For Input As #1For i = 1 To 20Forj = 1 To 6In put #1, a(i, j)Text1 = Text1 + Str(a(i, j) + Space(1)Next

18、jText1 = Text1 + Chr(13) + Chr(10)Next iClose #1End SubPrivate Sub Comma nd2_Click()=以下由考生编写 = =考生编写程序结束=End SubPrivate Sub Form_Unl oad(Ca ncel As In teger)Open App.Path & out5.dat For Output As #1Print #1, Text2.TextClose #1End Sub第五套1Private Sub Comma nd1_Click()Ran domize For k = ? To 9? = In t(

19、R nd * 90 + 10)Next kEnd SubPrivate Sub Comma nd2_Click() For k = 0 To ?temp = Label1(k).Capti onLabel1(k).C apti on = Label1(9 - k).C apti on? = tempNext kEnd Sub2Dim r%, xO%, yO, aPrivate Sub Comma nd1_Click()Timer1.E nabled = TrueEnd SubPrivate Sub Form_Load()r = Shap e1.Width / 2 xO = ? + ryO =

20、Shape1.Top + r Imagel .Left = x0 - ?Imagel.Top = yO - r - Imagel.Height / 2 a = 90End SubPrivate Sub Timer1_Timer()Dim x, ya = a - 3x = xO + r * Cos(a * 3.14159 / 180)y = yO - r * Si n(a * 3.14159 / 180)Image1 .L eft = ? - Image1.Width / 2Image1.Top = ? - Image1.Height / 2End Sub3Private Sub Comma n

21、d1_Click()Ope n i n5.dat For In put As #1n = L0F(1) ch$ = In put( n, ?)Close #1Text1.Text = chEnd SubPrivate Sub Comma nd2_Click()Dim IsSpace As Boolea n ch1$ = Text1.Text n = Len( ?)IsSpace = TrueFor k = 1 To nc = Mid(ch1, k, ?)个空格符If c = The n双引号中是IsSpace = TrueElseIf IsSpace The nc = UCase(c)IsSp

22、ace = FalseEnd IfEnd Ifch2$ = ch2$ & ?Next kText1.Text = ch2End SubPrivate Sub Comma nd3_Click()Ope n out5.dat For Output As #1Print #1, Text1.TextClose #1End Sub第六套1Private Sub Comma nd1_Click()str1 = Text1.Textstr2 = Text2.Text n = Len For i = 1 To LenIf Mid(str1, i, n) = RTrim(str2) ThenMsgBox st

23、r2 & 的起始位置是:&?Exit ForEnd IfNextIf 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 young man and a young woman were seat ing behi nd me. They were talki ng loudly.End Sub2Private S

24、ub showPic_Click()Picture1.Visible = TrueText1.Visible = False If ?=显示图片ThenPicture1.Picture = LoadPicture(App.Path & pic4.bmp) showPic.Caption = 清空图片ElsePicture1.Picture = ?showPic.Caption = 显示图片End IfEnd SubPrivate Sub showText_Click() Picture1.Visible = ?Text1.Visible = TrueOpe n App.Path & data4

25、.dat ? As #1In put #1, s Textl.Text = ?Close #1End Sub3Private Sub Comma nd1_Click()Ope n App.Path & data5.dat For In put As #1In put #1, xLabel1.Caption =?Close ?End SubPrivate Sub Comma nd2_Click()= 以下考生编写= = 考生编 写程 序结 束=Open App.Path & out5.dat For Output As #1Print #1, Label2.C apti onClose #1En

26、d SubPrivate Fun cti on p(n As In teger) As Boolea nflag = TrueFor i = 2 To Sqr( n)If n Mod i = 0 Thenflag = FalseExit ForEnd IfNext ip = flagEnd Fun cti on第七套1Private Sub Comma nd1_Click()For i = 0 To 6k = ?For j = i + 1 To ?If Val(Text1(j).Text) ? The nk = jEnd IfNext jj = Text1(i).TextText1(i).Te

27、xt = Text1(k).TextText1(k).Text = ?Next iEnd Sub2Private Sub Comma nd1_Click()For k = 0 To Combo1.ListCount - 1If Combo1.Text = ? The nExit ForEnd IfNext kIf k = Combol .ListCount ThenCombol.Addltem ?ElseMsgBox (此项目已存在!)End IfEnd SubPrivate Sub Comma nd2_Click()If Combol.List In dex = 0 Then Combol.

28、Removeltem ?End IfEnd SubPrivate Sub Comma nd3_Click() Textl.Text = Textl.Text & ” ” &End SubPrivate Sub Comma nd4_Click() ?=End Sub3Option Base 1Dim s As Stri ngPrivate Sub Comma nd1_Click()Ope n App.Path & in 5.dat For In put As #1 s = In put(LOF(1), #1)Close #1Text1.Text = sEnd SubPrivate Functio

29、n 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 The nch = ch + cElsem = m + 1words(m) = ch ch =End IfNext k GetWords = ?End Fun cti onPrivate Sub Comma nd2_Click()Dim ch(800) As String, n As IntegerIf Len(s) = 0 ThenMsgBox 请先使用“读数据”功能! Else

30、m = GetWords( ? , ch ) 考生编写的程序代码从这里开始 考生编写的程序代码到这里结束End IfEnd SubPrivate Sub Form_Unl oad(Ca ncel As In teger)Open App.Path & out5.dat For Output As #1Print #1, Label1.C apti onClose #1End Sub第八套Private Sub Comma nd1_Click()Dim s As LongDim i As In tegeri = 0: s = 0While i ? ?s = s + jc(i)WendTextl.

31、Text = sEnd SubFun cti on jc(n As In teger) As LongDim i As In tegerDim t As Long ?For i = 1 To ?t = t * iNext ?End Fun cti on2Option Base 1Private Sub Comma nd1_Click()Dim arr(50) As In tegerDim i As In teger, j As In tegerDim x As In teger, max As In teger, pos As In tegerRan domizemax = 0: pos =

32、1i = 1Dox = Int(Rnd * 101) ?Do While j iIf x arr(j) The nj = j + ?ElseExit DoEnd IfLoopIf j = i The narr(j) = ?Print arr(j);i = i + 1If (i - 1) Mod 10 = 0 The n PrintIf max 50Textl.Text = maxText2.Text = posEnd Sub3Dim a(100) As IntegerPrivate Sub Comma nd1_Click()Dim k As In tegerOpen App.Path & in

33、5.dat For Input As #1For k = 1 To 100In put #1, a(k)Next kClose #1End SubPrivate Sub Comma nd2_Click()Dim i As In teger, j As In tegerDim b(100) As In tegerj = 0For i = 1 To 100If prime(a(i) The nj = j + 1b(j) = a(i)End IfNextFori = 1 TojText1 = Text1 + Str(b(i)NextEnd Sub以下Function过程用于判断某数是否为质数Fun

34、cti on prime(p As In teger) As Boolea n考生编写End Fun cti onPrivate Sub Form_Unl oad(Ca ncel As In teger)Open App.Path & out5.dat For Output As #1Print #1, Text1.TextClose #1End Sub第九套Dim n As In tegerPrivate Sub Form_Click()Timer1.E nabled = ?End SubPrivate Sub Form_Load() Timerl.I nterval = ?Timerl.E

35、 nabled = FalseTextl.ForeColor = 0n = 0End SubPrivate Sub Timer1_Timer() n = ?If n Mod 5 = 0 The n Textl.Text = Time()End IfIf n Mod 8 = 0 The nIf Textl.ForeColor = ? The nTextl.ForeColor = &HFFElseTextl.ForeColor = 0End IfEnd IfEnd Sub2Dim a%(1 To 10)Private Sub Comma nd1_Click()Ran domizeFor k = 1

36、 To 10a(k) = Int(Rnd * 90 + 10) Picturel.Print a(k);Next kPicture1.Pri ntPicture1.Pri nt End SubPrivate Sub Comma nd2_Click()m% = Val(Text1) MoveArray a(), ?For k = 1 To 10Picture1.Print a(k);Next kPicturel.Pri ntEnd SubSub MoveArray(a() As In teger, m As In teger)n% = UBou nd(a) For k = 1 To ?x = a

37、(1)For j = 1 To n - 1a(j) = a( ?)Next ja(n) = ?Next kEnd Sub3Private Type recn ame As Stri ng * 3Math As In tegerChin ese As In tegerEn glish As In tegerEnd TypeDim a(30) As rec, num As In tegerPrivate Sub Comma nd1_Click()Ope n App.Path & in 5.txt For In put As #1k = 1 Do While Not EOF( ?)In put #1

38、, a(k) .n ame, a(k).Math, a(k).Chi nese, a(k).E nglishk = k + 1LoopClose #1 num = ?End SubPrivate Sub Comma nd2_Click()= 考生编写=IEnd SubPrivate Sub Comma nd3_Click()Open App.Path & out5.dat For Output As #1For k = 1 To numPrint #1, a(k) .n ameNext kClose #1End SubPrivate Fun cti on sum(k As In teger)

39、As In tegersum = a(k).Math + a(k).Chi nese + a(k).E nglishEnd Fun cti on第十套Private Sub Comma nd1_Click()If ? Or File1.ListI ndex = File1 丄 istCou nt - 1 ThenFile1.ListI ndex = 0ElseIf FilehListlndex = 0 ThenFile1.ListI ndex =?End IfEnd IfShow InforEnd SubPrivate Sub File1_DblClick()Call ShowI nforEn

40、d SubPrivate Sub ShowI nfor()Label1.Captio n = App.Path + +?Image1.Picture = LoadPicture(Label1.Captio n)End SubPrivate Sub Form_Load()File1.Path = App.PathFile1. ?End Sub2Private Sub Comma nd1_Click()Dim fstr As String, ostr As Stri ngDim times As In teger, pos As In tegerDim ans As In tegerfstr =

41、InputBox(输入待查内容 ,查找)If fstr = The nExit SubEnd Iftimes = 0ostr = Textl.Textpos = InStr(1, ostr, fstr)Do While pos 0Text1.SelStart = ?Textl.SelLe ngth = ?times = ?Text2.Text = timesans = MsgBox(找到了,是否继续查找?, vbYesNo)If ans = vbYes Thenpos = pos + Len(fstr) pos = ?ElseExit DoEnd IfLoopEnd Sub3Opti on E

42、xplicitOption Base 1Dim a(10) As In tegerPrivate Sub Comma nd1_Click()Dim i As In tegerListl.ClearOpen App.Path & in5.dat For Input As #1For i = 1 To 10In put #1, a(i)List1.Addltem (a(i)Next iClose #1End Sub强化31Private Sub Comma nd2_Click()=考生编写的程序=IEnd SubPrivate Sub Comma nd3_Click()Dim i As In te

43、gerOpen App.Path & out5.dat For Output As #1For i = 0 To 9Print #1, List2丄 ist(i)Next iClose #1End SubPrivate Sub C1_Click()Dim k As In teger Form2. ?Form2.Print Forml.Ll.Caption; Forml.TextlForm2.Pri nt Form1.L2.C aptio n; Form1.Text2Form2.Pri nt Form1.L3.C aptio n; Form1.Text3 Form2.Print Forml.Fr

44、amel. ?;:; For k = 0 To 1If Form1.Op1( ? ).Value The nForm2.Print Form1.Op1(k).CaptionEnd IfNext kEnd SubPrivate Sub Form_Load() Text2. ?= *End Sub2Private Sub C1_Click() If ? = 123456 The nTextl.Text = 口令正确Text1.?=ElseText2.Text = Text2.Text - 1If Text2.Text ? The n输入MsgBox 第& (3 - Text2.Text) & 次口

45、令错误,请重新IIElseMsgBox 3次输入错误,请退出 Text1.E nabled = ?End IfEnd IfEnd Sub强化32Private Sub Form_load()HScrolH.Min = Shape2.Left HScroll1.Max = Shape2.Width + Sh ape2.Left - Shape1. ?VScroll1.Min = Shap e2.TopVScrolll.Max = Shape2.Height + ? - Shapel.HeightHScrolll.Value = 1000VScrolll.Value = 1000End SubPrivate Sub HScroll1_Cha nge()? = HScroll1.ValueEnd SubPrivate Sub VScroll1_Cha nge() Shape1.Top = ?End Sub2Di

温馨提示

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

评论

0/150

提交评论