第二部分 VB程序设计
一、 选择题
21.以下所列的8个控件中,具有Caption属性的有 个。
CheckBox(复选框)、ComboBox(组合框)、HscrollBar(水平滚动条)、DirListBox(文件夹列表框)、Image(图像框)、Frame(框架)、Label(标签)、Line(线条)
A.5 B.4 C.3 D.2
22.执行下面语句后,Len函数值最大的是 。
Dim IA As Integer, B As Single, S As String *5, Ch As String
IA=32767 : B=23.5 : S=”A” :Ch=”abcd”
A.Len(IA)
B.Len(B) C.Len(S) D.Len(Ch)
23.假设变量Lng为长整形变量,下面不能正常执行的语句是 。
A
.
Lng=16384*2
B.Lng=4*0.5*16384
C.Lng=190^2 D.32768*2
24.数学表达式对应的正确Visual Basic表达式为 。
A.-b+Sqr(b*b-4*a*c)/2*a
B.-b+Sqr(b*b-4*a*c)/(2*a)
C.(-b+Sqr(b*b-4*a*c))/(2*a)
D.(-b+Sqr(b*b-4*a*c))/ 2*a
25.设Mys1,Mys2均为字符串型变量,Mys1=”Visual Basic”,Mys2=”b”,则下面关系表达式中结果为的是 。
A.Len(Mys1)<>2*InStr(Mys1,”1”)
B.Mod(Mys1,8,1)>Mys2
C.Chr(98)&Right(Mys1,4)=”Basic”
D.InStr(Left(Mys1,6),”a”)+60<Asc(Ucase(Mys2))
26.在窗体模块代码窗口的通用声明处,可以使用语句说明数组的是 。
① Public A(10) As Integer ② Dim A(10) As Integer
③ Private A(10)As Integer ④ Static A(10) As Integer
A.①② B.②③ C.③④ D.①④
27.设A=7,B=4,C=6,,则表达式A Mod3+B^3/C\5的值为 。
A.1 B.2 C.3 D.出错
28.下列说法中,错误的是 。
A.
当程序正常结束时,所有没用Close语句关闭的文件都会自动关闭
B.
在关闭文件或程序结束之前,可以不用Unlock语句对已锁定的记录解锁
C.
可以用不同的文件号同时打开一个随机文件
D. 用Output模式打开一个顺序文件,即使不对它进行写操作,原来内容也被清除
29.程序中有两个过程Private Sub Fun1(S As String)和Private Sub Fun2(a() As String 6),在调用过程中用Dim St(6) As String6定义了一个字符串数组。下面调用语句中正确的是 。
① Call Fun1(St(3)) ② Call Fun2(St) ③ Call Fun1(St) ④ Call Fun2(St(6) )
A.①②
B.①③ C.②③ D.②④
30.DrawStyle属性用于设置图形方法输出的线型,它受 属性的限制。
A.FillStyle B.FillColor C.BorderStyle D.DrawWidth
二、填空题
1.若窗体有列表框,则List1.List(List1.ListIndex)的值等于List1的__Text___属性值。
2.执行下面的程序,当单击Command1时,列表框List1的第2列表项内容是3 ,第4列表项内容是_15_,第5列表项内容是 28 。
Private Sub Command1_Click()
Dim I As Integer,j As Integer
For I =1 To 10
j=I+j
List1.AddItem j
Next I
For I =1 To 4
List1.RemoveItem List1.ListCount - I
Next I
End Sub
3.运行下面的程序,当单击Command1时,窗体上显示的第一行内容是DCB,第三行内容是D,第四行内容是3。
Private Sub Command1_Click()
Print Text(3)
End Sub
Private Function Text(t As Integer)As Integer
Dim i As Integer
If t>=1 Then
Call Test(t-1)
For i = 3 To t Step - 1
Print Chr(Asc(“A”)+ i);
Next i
Print
End if
Test = t
End Function
4.运行下面的程序,当单击窗体时,窗体上显示的第一行内容是10 8,第三行内容是5 2,第四行内容是12 -10。
Dim x As Integer,y As Integer
Private Sub Form_Click()
Dim a As Integer,b As Integer
A=5:b=3
Call sub1(a,b)
Print a,b
Print x,y
End sub
Private Sub sub1(ByVal m As Integer,n As Integer)
Dim y As integer
X=m+n:y=m-n
M=fun1(x,y)
N=fun1(y,x)
End sub
Private Function fun1(a As Integer,b As Integer)As Integer
X=a+b:y=a-b
Print x,y
Fun1=x+y
End function
5.执行下面的程序,当单击COMMAND1时,picute1中显示内容的第二行与第四行分别是5 6 7 8与13 14 1516,picture2中显示内容的第一行和第三行分别是4 8 12 16与2 6 10 14。
Private Sub Command1_Click()
Dim a(4,4)As Integer,I As Integer,j As Integer
Dim b(4,4)As Integer
For I=1 To 4
S=“”
For j =1to 4
A(I,j)=((I-1)*4+j)
S=s&Right(“ “& Str(a(I,j)),3)
Next j
Picture1.Print s
Next i
For I=1 To 4
For j=1 To 4
B(5-j,I)=a(I,j)
Next j
Next i
For I=1 to 4
S=“”
For j = 1 To 4
If Len((CStr(b(I,j)))<2 Then
S=s&“” & CStr(b(I,j))&“ “
Else
S=s& CStr(b(I,j))&“ “
End if
Next j
Picture2.Print s
Next i
End Sub
6.下面程序的功能时,输入x的值,利用递推法分别求出级数前n项(n=0,1,2,3…)之和。
S=a0+a1+…+an+…
其中,
a 0=1 a n=a n-1 * n=1,2,3……
计算积数,直到第n项的绝对值小于等于0.001时停止,完善程序,实现以上功能。
Option Explicit
Private Sub Command1_Click()
Dim x As Single, I As Integer, s As Single
Dim a As Single, a1 As Single
X = Text1
A=1:s = a
List1.AddItem“s(“&“0)=” & Str(s)
Do
I=I+1
____
a1=a*x*(3-2*i)/(2*i)___
___
S=s+a1
List1.AddItem“s(” &CStr(I)&“)=” & Str(s)
If Abs(a1)〈=0.001 Then
Text2=i
Exit do
Else
A=a1
End if
Loop
End Sub
7.下面程序的功能时,验证任意一个大于5的奇数可表示为3个素数之和。完善程序,实现以上功能。
Option Base 1
Private Sub Command1_Click()
Dim P()As Integer,N As Integer,L As Integer
Dim I As Integer,J As Integer,k As Integer
Dim ch As String
N=InputBox(“输入一个大于5的奇数!”)
Label1.Caption= str(n) & “=”
Call Prime(P,N)
L=Ubound(P)
For I=1 to L
For J=1 to L
For k =1 to L
Ifp(i)+p(j)+p(k)=n then
Ch=CStr(P(I)&“+” &CStr(P(J))&“+” & CStr(P(k))
Text1.text = ch
Exit sub
End if
Next k
Next J
Next I
End sub
Private Sub Prime(A()As Integer,N As Integer)
Dim I As Integer,Idx As Integer
Dim J As Integer
For I=2 to N
For J = 2 To Sqr(I)
If I Mod J =0 Then Exit For
Next J
If J>Sqi(I) then
__
_idx=idx+1___
_
__
redim preserve A(idx)
a(idx)=I
end if
8.将20个棋子围成一圈,按顺时针方向从1-20给棋子编号,从中取出棋子的规则是:从某编号棋子开始取出第1个棋子,然后按顺时针方向围绕周数棋子,从1数到2取第2个,再从1数到3取第3个,再从1数到4取第4个……直到取完。本程序的功能就是找出依照上述规则取棋子的编号序列,使得最后一个被取棋子的编号为指定的编号。例如:若指定最后取棋子的编号为9,则必须从编号为17的棋子开始取第一个棋子,取棋子的顺序是:17,19,2,6,11,18……。完善程序,实现以上功能。
Option base 1
Private sub command1_click()
Dim a(20) as integer,I as integer,k as integer
Dim n as integer,number as integer,s as string
Number=val(text2)
<![endif]> For k=1 to 20
For I=1 to20
A(i)=1
Next I
S=_left(cstr(k) & “--”,3)
Call sub1(a,k,n,s)
If n=number then
Text1=s
Exit for
End if
Next k
End sub
Private sub sub1(a() as integer,byval idx as integer,n as integer,s as string)
Dim I as integer,js as integer,sum as integer
Dim ub as integer,step as integer
_____ub=ubound(A)__________
js=1:stemp=1
a(idx)=0
do while js<20
step=step+1
____sum=0_______
do while sum<stemp
idx=idx+1
if idx>ub then ____idx =idx mod ub___
sum=sum+a(idx)
loop
a(idx)=0
s=s & left(cstr(idx) & “ ”,3)
____js=js+1______
if js mod 10=0 then s=s & vbcrlf
loop
n=idx
end sub
9.C盘根目录下的数据文件data.txt中有两组数据,第一组数据未排序,并以-1表示该组数据结束;第二组数据按从小到大顺序排列。下面程序的功能是,单击“读入数据”按钮,将文件中的两组数据,分别读入到A、B数组中,单击“插入排序”按钮,则把A数组的元素按其大小依次插入到B数组的适当位置,使得B数组中元素仍为从小到大排列。完善程序,实现以上功能。
Dim a() as integer, b() as integer
Private sub command1_click()
Dim I as integer,j as integer,n as integer, s as string
__
open “c:\data.txt” for input as #11__
do
input #11,n
if n=-1 then exit do
I=I+1
<![endif]> Redim preserve a(i)
A(i)=n
S=s & str(a(i))
Loop
Text1=s
S=””
___Do while not eof(1)__
j=j+1
redim preserve b(j)
input #11,b(j)
s=s & str(b(j))
loop
text2=s
close 11
end sub
private sub command2_click()
dim I as integer, j as integer, s as string
for I=1 to ubound(a)
if a(i)<b(1) then
call change(a(i),1)
elseif a(i)>b(ubound(b)) then
___redim preserve b(ubound(b)+1)___
b(ubound(b))=a(i)
else
for j=2 to bound(b)
if(a(i)>b(j-1)) and a(i)<=b(j) then call change(a(i),j)
next j
end if
next I
for I=1 to ubound(b)
s=s & str(b(i))
next I
text3=s
end sub
private sub change( n as integer,k as integer)
dim I as integer
redim preserve b(ubound(b)+1)
for I=ubound(b) to k+1 step –1
_____b(I)=b(I-1)_
next I
____b(k)=n__
end sub
posted on 2006-10-21 09:28
木子李 阅读(1939)
评论(5) 编辑 收藏 引用 网摘 所属分类:
Visual Basic 课堂