29.下面有关数组的说法中,错误的是( )
A.数组必须先定义后使用
B.数组形参可以是定长字符串类型
C.Erase语句的作用是对已定义数组的值重新初始化
D.定义数组时,数组维界值可以不是整数
30.可以把变化长字符串S中的第一个"ABC"子串,替换成“1234"的语句是( )
A. S=Left(s, InStr(S,"ABC"))&"1234" & Right(S,Len(S)-InStr(S,"ABC")-2)
B. Mid(S,InStr(S,"ABC"),3)="1234"
C. Mid(S,InStr(S,"ABC"),4)="1234"
D. S=Left(s, InStr(S,"ABC")-1)&"1234"& Right(S,Len(S)-InStr(S,"ABC")-2)
二 填空题
1. 执行下面程序,当单击窗体时,显示在窗体上第一行的内容是 200 ,第二行的内容是 10
Private Sub Form_Click()
Dim I As Integer,Sum As Intger
For I=0.5 To 8.5 Step2.5
Sum=Sum+I*10
Next I
Print Sum
print I
End Sub
2.运行下面的程序,当单击窗体时,窗体上显示的内容的第一行是 0:1 ,第三行是 2:3 ,第五行是 4:1 。
Private Sub From_Click()
Dim s As String, i As Integer,n(9) As Integer
Dim s1 As String*1,j As Integer
s=Trim("12345a307291b233")
For i=1 To Len(s)
s1=Mid(s,i,1)
If s1>="0" And s1<="9"Then
j=Val(s1)
n(j)=n(j)+1
End If
Next i
For j=0 To 9
Print j; ":" ;n(j)
Next j
End Sub
3.执行下面程序,单击命令按钮Command1后,显示在窗体上第一行的内容是 11 ,第二行的内容是 61
最后一行的内容是 136
Option Explicit
Dim N As Integer
Private Sub Command1_Click()
Dim I As Integer, J As Integer
For I=3 To 1 Step -2
N=Fun(I,N)
Print N
Next I
End Sub
Private Function Fun (A As Integer) As Integer
Static X As Integer
Dim Sum As Integer,I As Integer
X=X+N
For I =1 To A
B=B+X+I
N=N-I\2
Sum=Sum+B
Next I
A=A+1
Fun=Sum+A
End Function
4.执行下面程序,单击命令按钮Command1后,显示在窗体上第一行的内容是 00 00 02 ,A(2,1)的值是 08 ,
A(3,3)的值是 03
Option Base 1
Private Sub Command1_Click()
Dim A(3,3) As Integer,K As Integer
Dim I As Integer,j As Integer
Call SUB1(A)
For I=1 To 3
For J= 1 To 3
Print Right("0"&A(I,J)&" ",3);
Next J
Print
Next I
End Sub
Private Sub SUB1(A() As Integer)
Dim N As Integer,K As Integer, J As Integer
N=UBound(A,1)
For I=1 To N-2
For J= I To N-I
A(I,J)=K+1
A(J,N+1-I)=K+2
A(N+1-I,N+1-J)=K+3
A(N+1-J,I)=K+4
K=K+4
Next J
Next I
If N Mod 2<>0 Then
A((N+1)/2, (N+1)/2)=K+1
End If
End Sub
5.执行下面程序,单击命令按钮Command1后,显示在窗体上第一行的内容是 4 , 第二行的内容是 8 ,
第三行的内容是 16 。
Option Explicit
Private Sub Command1_Click()
Dim N As Integer, M As Integer
N=2
DO While m<3
N=N+2
If Fun(N) Then
Print N
M=M+1
End If
Loop
End Sub
Private Function Fun(ByVal N As Integer) As Boolean
If N/2=Int(N/2)Then
Fun=Fun(N/2)
Else
If N=1 Then Fun=True
End If
End Function
6.在下面程序中,Command1_Click()事件过程的功能是生成一个5x5的矩阵,该矩阵的副对角线(指矩阵左下角
到矩阵右上角连线上的元素)上方元素都是偶数,副对角线和它的下方元素都为奇数。Command2_Click()事件
过程的功能是,交换以副对角线为界线的上三角和下三角的对应元素。完善程序,实现以上功能。
Option Explicit
Option Base 1
Dim A(5,5) As Integer
Private Sub Command1_Click()
Dim I As Integer,J As Integer , N As Integer
Randomize
For I=1 To 5
For J=1 To 5
Do
N=Int(rnd*90)+10
If J <=5-I And N Mod 2=0 Then
A(I,J)=N
ElseIf J >5-I And N Mod 2<> 0 Then
A(I,J)=N
End If
Loop ___until true
Text1=Text1 & Str(A(I,J))
Next J
Text1=Text1 & vbCrLf
Next I
End Sub
Private Sub Command2_Click()
Dim I As Integer,L As Integer,T As Integer
Dim J As Integer,R As Integer
For I =1 To 5
For J=1 To 5-I
T=A(I,J)
L=6-i
R=6-j
A(I,J)=A(L,R)
A(L,R)=T
Next J
Next I
For I =1 To 5
For J =1 To 5
Text2=Text2 & Str(A(I,J))
Next J
Text2=Text2 & vbCrLf
Next I
End Sub
7. 在下面程序中,Command1_Click()事件过程的功能是将26个大写字母A~Z依次写到二进制文件Myfile中,Command2_Click()
事件过程的功能是将文件中的大写字母在原位置——改写成小写字母,完善程序,实现以上功能。
Option Explicit
Dim S As String*1
Private Sub Command1_Click()
Dim I As Integer
For I=0 To 25
S=Chr(Asc("A")+I)
Put #12, , S
Next I
End Sub
Private Sub Command2_Click()
Dim Rc_NO As Integer
Seek #12, 1
Do While Not Eof(12)
S=input(1,#12)
S=LCase(S)
Rc_NO=Rc_NO+1
Put #12,Rc_NO, S
Loop
End Sub
Private Sub From_Load()
Open"e:\Myfile" For Binary As #12
End Sub
8.下面程序的功能是对密文解密。密文的加密方法是以字符为单位,取其ASCII码,按逆序保存(例如字母"e"的ASCII码是01100101,密文中则为10100110)。解密是加密的逆过程。完善程序,实现以上功能。
Private Sub Command1_Click()
Dim s As String, st As String, i As Integer,n As Integer
s=Text1
Do Until n >=Len(s)
n=n+1
If n Mod 8 <> 0 Then
st=st &Mid(s,n,1)
Else
st=st & Mid(s,n,1)
List1.AddItem st
st=" "
End If
Loop
End Sub
Private Sub Command2_Click()
Dim s As String, st As String, i As Integer
For i=0 To List1.Listcount
st=List1.List(i)
For j=1 To Len(st)
s=Mid(st,j,1) & s
Next j
For j=Len(s) To 1 Step-1
n=n+2^(j-1)
Next j
Text2=Text2 & Chr(n)
s=" "
n=0
Next i
End Sub
9.下面程序的功能是,找出100以内所有可以表示成3个连续自然数之和的数。完善程序,实现以上功能。
Option Explicit
Private Sub Command1_Click()
Dim I As Integer, N As Integer
Dim Js As Integer, S As String
For I =1 To 100
If Fun(I,N,Js)Then
S=Str(I) & "=" & N
Do while n<=js-1
N=N+1
S=S & "+" & N
Loop
List1.AddItem S
End If
Next I
End Sub
Private Function Fun(L As Integer, M As Integer, Js As Integer) As Boolean
Dim I As Integer, Sum As Integer, K As Integer
For I =1 To L
Sum=0
K=0
Js=i-1
Do While Sum < L And K < 3
K=K+1
Js=Js+1
Sum=Sum+Js
Loop
If k=3 And Sum=L then
M=I
Fun=True
E xit For
Exit if
Next I
End Function