1、计算机2级Option Base 1 Dim Arr1(20) As IntegerDim Arr2(20) As Integer Dim Sum as IntegerSub ReadData1()Open App.Path & & datain1.txt For Input As #1 For i = 1 To 20 Input #1, Arr1(i) Next I Close #1 End SubSub ReadData2() Open App.Path & & datain2.txt For Input As #1 For i = 1 To 20 Input #1, Arr2(i)Nex
2、t i Close #1 End SubSub WriteData(Filename As String, Num As Integer) Open App.Path & & Filename for Output As #1 Print #1, Num Close #1 End SubPrivate Sub C1_Click() ReadData1 ReadData2 End Sub Private Sub C2_Click() Dim arr3(20) As Integer Sum = 0 For i = 1 To 20arr3 (i) = Arr1(i) - Arr2(i) Sum =
3、Sum + arr3(i) Next Print Sum End Sub Private Sub C3_Click () WriteData dataout.txt, SumPrivate Function isprime(a As Integer) As Boolean Dim flag As Boolean flag = True b% = 2 Do While b% = 50 ThenText1.Text = Text1.Text & Arr(i) & Space(5) temp = temp + Arr(i) End If Next I Print temp End Sub Priva
4、te Sub Read_Click() ReadData End SubPrivate Sub Save_Click() WriteData dataout.txt, temp End Sub第四种100个整数下标为偶数的元素显示在文本框中,求合并显示Private Sub Calc_Click() For i = 1 To 100 If i Mod 2 = 0 Then Text1.Text = Text1.Text & Arr(i) & Space(2)sum = sum + Arr(i) End If Next i Print sum End SubPrivate Sub Form_Lo
5、ad() Text1.Text = End SubPrivate Sub Read_Click() ReadData End SubPrivate Sub Save_Click() WriteData dataout.txt, sum End Sub第五种100个整数数组中小于50的元素在文本框中显示,并求和显示Private Sub Calc_Click() For i = 1 To 100 If Arr(i) 50 Then Text1.Text = Text1.Text & Arr(i) & Space(2)sum = sum + Arr(i) End If Next I Print s
6、um End SubPrivate Sub Read_Click() ReadData End SubPrivate Sub Save_Click() WriteData dataout.txt, sum End Sub3,7,11计算5000以内能被该数整除的所有数之和,放在Text1中Private Sub C1_Click() If Cb1.Text = 3 Then divide (3) ElseIf Cb1.Text = 7 Then divide (7) Else divide (11) End ifPrivate Sub divide(x As Integer) Dim i As
7、 Integer Dim temp As LongFor i = 1 To 5000 If i Mod x = 0 Then temp = temp + I End If Next I Text1.Text = temp End sub 1一个命令按钮一个文本框0-1000能被5或7整出的整数个数显示Sub SaveData() Open App.Path & & outtxt.txt For Output As #1 Print #1, Text1.Text Close #1 End SubFunction Fun() Dim temp As Integer Dim i As Integer
8、 For i = 0 To 1000 If i Mod 5 = 0 or i Mod 7 = 0 Thentemp = temp + 1 End If Next I Fun = temp End FunctionPrivate Sub Command1_Click() d = Fun() Text1.Text = d SaveData End Sub2在0-100一个命令按钮一个文本框不能被7整除的所有整数的和在文本框显示Function Fun() Dim i As Integer Dim temp As Integer For i = 0 To 100 If i Mod 7 0 Then
9、temp = temp + I End If Next I Fun = temp End Function3在0-1000一个命令按钮一个文本框不能被7整除的所有整数的个数显示在文本框Function Fun() Dim i As Integer Dim temp As Integer For i = 0 To 1000 If i Mod 7 0 Then temp = temp +1 End If Next I text1.text= temp 4在0-200一个命令按钮一个文本框能被3整除的所有整数的和显示在文本框Function Fun() Dim sum As Integer, i A
10、s Integer For i = 0 To 200 If i Mod 3 = 0 Then sum = sum + I End If Next I Text1.Text = sum End Function5在0-100一个命令按钮一个文本框所有偶数的平方和,显示在文本框Function Fun()Dim i As Integer, sum As Long For i = 0 To 100 If i Mod 2 = 0 Then sum = sum + i * iEnd If Next I Text1.Text = sum End FunctionPrivate Sub Command1_C
11、lick() Image1.Picture = LoadPicture(App.Path & Misc34.ico) End SubPrivate Sub Command2_Click() Image1.Picture = LoadPicture(App.Path & Misc37.ico) End SubPrivate Sub Command3_Click()Image1.Picture = LoadPicture() End SubPrivate Sub Dir1_Change() File1.Path = Dir1.Path End SubPrivate Sub Drive1_Chang
12、e() Dir1.Path = Drive1.Drive End SubPrivate Sub File1_Click() Label2.Caption = File1.FileNameEnd SubOption Base 1 Dim a(5, 8) As Single, athlete(5) As String * 8Private Sub Command1_Click () Dim ch As String Text1 = Open App.Path & in5.dat For Input As #1 For k = 1 To 5Input #1, ch athlete(k) = ch T
13、ext1 = Text1 & ch & For j = 1 To 8 Input #1, ch a(k, j) = Val(ch)Text1 = Text1 & ch & Next Text1 = Text1 & Chr(13) & Chr(10) Next k Close #1 End SubPrivate Function getmark(n As Integer) As Singles = a (n, 1) maxnum = s minnum = s For k = 2 To 7s = s + a(n, k) If maxnum a(n, k) Then minnum = a(n, k)
14、 End IfNext k s = (s - maxnum - minnum) / 5 getmark = s * 3 * a (n, 8) End FunctionPrivate Sub Command2_Click() 要求考生编写的程序 Dim Sorce (5) As Single Dim i As Integer Dim maxSorce As Single Dim maxnum As Integer for i = 1 To 5Sorce (i) = getmark (i) Next maxSorce = Sorce (1) For i = 2 To 5 If Sorce (i)
15、maxSorce ThenMaxSorce = Sorce (i) maxnum = I End If Next Text2.Text = athlete(maxnum) Text3.Text = maxSorce End SubPrivate Sub Command3_Click() Open App.Path & out5.dat For Output As #1 Print #1, Text2, Text3 Close #1End SubPrivate Sub C1_Click() Dim k As Integer Form2.Show Form2.Print Form1.L1.Capt
16、ion; Form1.Text1 Form2.Print Form1.L2.Caption; Form1.Text2 Form2.Print Form1.L3.Caption; Form1.Text3 Form2.Print Form1.Frame1.Caption; :; For k = 0 To 1 If Form1.Op1(k).Value Then Form2.Print Form1.Op1(k).Caption End If Next k End SubPrivate Sub Form_Load() Text2.PasswordChar = *Private Sub C1_Click
17、() Dim k As Integer k = 0 While (k = a And b$ = A And b$ z Or c Z And c a Then c = String (1, Asc(c) - 26) End If a = a + c Next k Text2.Text = a End sub 打开文件默认为“文本文件”转换是把文本框中小写转换成大写,存盘是存在out5.dat文件中Private Sub C1_Click() Dim a As String CD1.Filter = 所有文件|*.*|文本文件|*.txt|Word文件|*.doc| CD1.FilterIndex
18、 = 2 CD1.Action = 1 Open CD1.FileName For Input As #1 Input #1, a Close #1Text1.Text = aPrivate Sub C2_Click() Text1.Text = UCase (Text1.Text) End Sub Private Sub C3_Click() CD1.FileName = out5.dat CD1.Action = 2 OpenCD1.FileName For Output As #1 Print #1, Text1.Text Close #1Private Sub Command1_Cli
19、ck() Text4 = a = Val(Text1) b = Val(Text2) n = Val(Text3) Text4 = Text4 & a & & b k = 2 Do While k n c = a * b k = k + 1 If c 10 Then Text4 = Text4 & & ca = b b = c Else d = c 10 Text4 = Text4 & & d a = d k = k + 1 If k = n Then d = c Mod 10 Text4 = Text4 & & d b = d End If End If Loop End Sub30个099
20、9的随机整数放入一个数组中,然后输出最大值,显示在窗体Private Sub Command1_Click() Dim arrN(30) As Integer Dim Max As Integer Randomize For i = 1 To 30 arrN(i) = Int(Rnd * 1000) Next i Max = arrN(1) For i = 2 To 30 If Max 500 Then Sum = Sum + arrN(i) End If Next I Print SumPrivate Sub Command1_Click() 20个0-999的整数求平均值Dim arrN(20) As Integer Dim Aver As Single Dim Sum As Integer, i Randomize For i = 1 To 20 arrN(i) = Int(Rnd * 1000) Next i Sum = 0 For i = 1 To 20Sum = Sum + arrN(i) Next i Aver = Sum / 20 Print Aver单击取数按钮,则把15个姓名读到数组a 中,并显示在窗体。Text中输入姓名或姓氏单
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1