文档库 最新最全的文档下载
当前位置:文档库 › vb程序阅读题与填空题

vb程序阅读题与填空题

vb程序阅读题与填空题
vb程序阅读题与填空题

VB程序阅读题与程序填空题综合练习

1、阅读下面程序,当单击窗体之后,窗体上输出的是。

Private Sub Form_Click( )

Dim i As Integer, j As Integer

Dim k As Integer

k=0

For i = 0 To 10 Step 3

For j = 1 To 10

If j > = 5 Then i = i +4: Exit For

j = j + 1

k = k + 1

Next

If i > 8 Then Exit For

Next

Print k

End Sub

2、阅读下面的事件过程。单击窗体后,在文本框Text1和Text2中显示的内容分别

是和;若将程序中A语句与B语句的位置互换,再次执行程序,单击窗体后在Text1和Text2中显示的内容分别是和。

Private Sub Form_Click( )

Dim x As Integer, y As Integer

x = 1 : y = 0

Do While x < 3

y = y + x 'A语句

x = x + 1 'B语句

Loop

Text1.Text = x

Text2.Text = y

End Sub

3、下面程序段中,k循环共执行次,在窗体上显示的结果是。

Dim b As Integer, k As Integer

b = 1

For k =1 To 5

b = b * k

If b > = 15 Then

Exit For

Else

k = k + 1

End If

Next k

Print k, b

4、以下是按钮cmdl的Click事件过程,求1~100之间的所有质数。质数的个数显示在窗

体上,在划线处填上缺少的内容。

Private Sub cmdl_Click( )

Dim intNum As Integer, int1 As Integer, int2 As Integer

intNum = 0

For int1 =

For int2 = 2 To int1 \2

If (int1 Mod int2) = 0 Then

intNum=1

End If

Next

If

sNum = sNum + 1

End If

Next

Print

End Sub

5、若命令按钮的名称为CmdExit,程序要求单击以上命令按钮时,程序停止运行。请在画线处中填入适当的内容。

Private Sub CmdExit_ ( )

End Sub

6、下面的事件过程判断文本框txt1中输入的数所在区间,并在文本框txt2中输出判断结果。在画线处填入正确的内容。

Private Sub Comandl_Click( )

Dim int1 As Integer

int1 =val (txt1.Text)

Select Case int1

Case

txt2.Text = "值为0"

Case

txt2.Text = "值在1和10之间(包括1和10)"

Case

txt2.Text = "值大于10"

Case Else

txt2.Text = "值小于0"

End Select

End Sub

四、读程序题,写出程序运行结果。

1.运行结果:

Private Sub Form_Click()

For I = 1 To 9

For j = 1 To 30 - 3 * I

Print " ";

Next j

For k = 1 To I

Print k;

Next k

For k = I - 1 To 1 Step -1

Print k;

Next k

Print

Next I

End Sub

2.运行结果:

Private Sub Command1_Click() Static S As Integer

Dim i As Integer

S = 1

For i = 1 To 5

S = S * i

Next i

Print S

End Sub

3.运行结果:

For X = 5 To 1 Step –1 For Y = 1 To 6 - X

Print Tab(Y + 5); "*";

Next Y

Print

Next X

4.运行结果:

S = 0: T = 0: U = 0

For X = 1 To 3

For Y = 1 To X

For Z = Y To 3

S = S + 1

Next Z

T = T + 1

Next Y

U = U + 1

Next X

Print S; T; U

5.运行结果:

Private Sub Command1_Click() Dim b As Integer

a = 3.6

b = 3.6

Text1.Text = a

Text2.Text = b

End Sub

2.以下程序判断从文本框Text1中输入的数据,如果该数据满足条件:除以3余2,除以5余3,除以7余4,则输出;否则将焦点定位在文本框Text1中,选中其中的文本。

Private Sub Command_Click()

X = Val(Text1.Text)

If (1)Then

Print X

Else

(2) (3)

(4) End If

End Sub 五、编程题 1.设计一个计算程序。该程序用户界面如图所示,由四个文本框:文本框1(text1)、文本框2(text2)、文本框3(text3)、文本框4(text4),和三个按钮:命令按钮1(command1)、命令按钮2(command2)、命令按钮3(command4)组成.程序运行后,用户按清除按钮,则清除文本框中显示的内容,按计算按钮,则计算三科平均成绩。单击退出按钮则退出。 Private Sub Command1_Click() Text1.Text =

[1] Text2. [2] = ""

[2] [3]

.Text = ""

[3]

End Sub

Private Sub Command2_Click() If Text1. [4]= " " Or Text2.Text = [5] Or Text3.Text = " " Then

[4] MsgBox "成绩输入不全!" [5]

Else

Text4.Text = ( [6 ] + Val(Text2.Text)

[6] + Val(Text3.Text)) / [7 ] [7]

[8 ]

[8]

End Sub

Private Sub Command3_Click()

命令按钮1command1

命令按钮2command2

命令按钮3

command3文本框1(text1)

文本框2(text2)文本框3(text3)

文本框4(text4)

Unload [9] [9] [10] Sub [10]

3.设计一个欢迎程序。该程序用户界面如图所

示。要求程序运行后,用户选中粗体复选框时

“欢迎您!”几个字的字体变成粗体,用户选中

斜体复选框时“欢迎您!”几个字的字体变成斜

体。若取消选中,则恢复原字体。按结束,则退

出。

4.任给3个数,求其中间数,写出程序代码。

三、阅读程序题

1.阅读下列程序并写出程序运行结果

Private Sub Form_Click()

Dim s As Long, f As Long, n As Integer, i As Integer n = 3

For i = 1 To n

f = f + i

s = s + f

Next

Print "s="; s

End Sub

写出程序运行时单击窗体后,窗体Form1上的输出结果。

运行结果:

2.阅读下列程序并写出程序运行结果

Private Sub Command1_Click()

x = 0

Do While x < 100

x = (x + 2) * (x + 4)

n = n + 1

Loop

Text1.Text = Str(n)

Text2.Text = Str(x)

Text3.Text = Val(Text1.Text) + Val(Text2.Text)

End Sub

文件框Text3的结果是:

运行结果:

3.阅读下列程序并写出程序运行结果

Private Sub Command1_Click()

Dim Sum1 As Integer, Sum2 As Integer

Sum1 = 0: Sum2 = 1

For I = 1 To 4

For J = 1 To I

Sum2 = Sum2 * J

Next J

Sum1 = Sum1 + Sum2

Next I

Print Sum1

End Sub

写出程序运行时单击命令按纽后,窗体上的输出结果。

运行结果:

4.阅读下列程序并写出程序运行结果

Private Sub Command1_Click()

Dim x As Integer

Static s As Integer

x = Val(InputBox("请输入一个正整数

If x < 6 Then

s = s * x

Else

s = s + x

End If

Text1.Text = "s=" & Str(s)

End Sub

程序运行时连续3次单击Command1,且设输入

的数据为6、5、4时,分别写出文本框Text1

5.阅读下列程序并写出程序运行结果

Private Sub Form_Click()

Dim A(1 To 3) As String

Dim c As Integer,j As Integer

A(1) = “2”

A(2) = “4”

A(3) = “6”

c=0

For j=1 to 3

c = c + Val(A(j))

Next j

Print c

End Sub

写出程序运行时单击窗体后,窗体Form1上的结果:

运行结果:Array 7.阅读下列程序并写出程序运行结果

Sub test(i As Integer)

i = i + 1

End Sub

Private Sub Form_Click()

Dim x As Integer

x = 4

Print "x="; x

Call test(x)

Print "x="; x

End Sub

8.阅读下列程序并写出程序运行结果

Private Sub Form_Click()

a = 1:

b = 1

Print "A="; a; ",B="; b

Call mult(a)

Print "A="; a; ",B="; b

End Sub

Private Sub mult(x)

x = 2 * x

b = 3 * b

End Sub

9.阅读下列程序并写出程序运行结果

Private Sub Form_Click()

Dim i As Integer, a As Integer

k = 0

For i = 1 To 6

If i > 3 Then

a = a + 4

Else

a = a + 1

End If

Next i

Print i, a

End Sub

写出程序运行时单击窗体后,Form1上的输出结果。

10.阅读下列程序并写出程序运行结果

Sub Change(ByVal x As Integer, ByVal y As Integer)

Dim t As Integer

t=x

x=y

y=t

Print x,y

End sub

Private Sub Form_Click()

Dim a As Integer, b As Integer

a = 3:

b = 4

Change a, b

Print a,b

End Sub

写出程序运行时单击窗体后,Form1上的输出结果

(20) 下列程序段执行结果为( )

x=5

y=-6

If Not x>0 Then x=y-3 Else y=x+3

Print x-y; y-x

A) -3 3 B) 5 -9 C) 3 -3 D) -6 5

(23) 单击命令按钮时,下列程序的执行结果为( )

Private Sub Command1_Click()

Dim x As Integer, y As Integer

x=12:y=32

Call Proc(x,y)

Print x; y

End Sub

Public Sub Proc(n As Integer, ByVal m As Integer)

n=n Mod 10

m=m Mod 10

End Sub

A) 1232 B) 232 C) 23 D) 123

二、填空题

(1) 完成下面的程序,使显示结果如下图所示。

Private Sub Form_Click()

FontSize=18

Sample$=" 【1】 "

x=(ScaleWidth-TextWidth(Sample$) ) /2

y=(ScaleHeight-TextHeight(Sample$) ) /2

CurrentX=x

CurrentY=y

【2】 Sample$

End Sub

(2) 下列程序的功能是:当x<50时,y=0.8×x;当50≤x≤100时,y=0.7×x;当x>100时,没有意义。请填空。

Private Sub Command1_Click()

Dim x As Single

x=InputBox("请输入x的值!")

【3】

Case Is < 50

y=0.8 * x

Case 50 To 100

y=0.7 * x

【4】

Print "输入的数据出界!"

End Select

Print x, y

End Sub

35.窗体上有Text1、Text2两个文本框及一个命令按钮Command1,编写下列程序:

Dim y As Integer

Private Sub Command1_Click()

Dim x As Integer

x=2

Text1.Text= p2(p1(x),y)

Text2.Text= p1(x)

End Sub

Privage Function P1(x As Integer) As Integer

x =x+y:y=x+y

P1=x+y

End Function

Private Function P2(x As Integer, y As Integer) As Integer

P2= 2*x+y

End Function

当单击1 次和单击2次命令按钮后,文本框Text1和Text2内的值分别是(C)

31.如下程序,运行的结果是(B)

Private Sub Form_Click()

Dim m As Integer,i As Integer,x(10) As Integer

For i= 0 to 4

Next i

For i=1 to 2

Call proc(x)

Next i

For i= 0 to 4

Print x(i);

Next i

End Sub

Public Sub proc(a() As Integer)

Static i As Integer

Do

a(i)=a(i)+a(i+1)

i=i+1

Loop While i<2

End Sub

32.假设有以下程序段:

For I=1 to 3

For j=5 to 1 Step -1

Print I*j

Next j

Next I

则语句Print I*j的执行次数I、j的值分别是(A)

33.在窗体上一个文本框,其名称为Text1,然后编写如下事件过程:

Private Sub Text1_KeyPress(KeyAscii As Integer)

Dim str As String ,n As Integer

str = UCase (Chr(KeyAscii))

n=Len(str)

Text1=String(n, str)

End Sub

程序运行后,如果在键盘上输入单字母"K",则在文本框Text1中显示的内容为()

5.下面的程序输入X的值,按以下公式求Y值。

1001000

1000100

400100200

X X

Y X X

X

--≤

?

=+≤≤

?

?<≤

?

Private Sub Command1_Click()

X=Val(Text1.Text)

Select Case X

Case 【1 】

Print "X<-100 OR X>200"

Case 【2 】

Y=100-X

Case 【3 】

Y=100+X

Case 【4 】

Y=400

End Select

Text2.Text=Y

End Sub

6.以下程序是利用公式

1111

4*()

1357

π=-+-+来计算π的值。其中,变量k表示当

前符号项,t表示当前项,n表示当前项的序号,要求精度控制在0.00001内。试分析程序,完成空格处填的内容。

Dim pi As Single,t As Single

Dim n As Single,k As Single

pi=0 : n=1

k=1 : t=1

Do While(【1 】)

pi =pi+t

k=-k

t=【2 】

n=n+1

Loop

pi=【3 】

Print "pi=";pi

7.下列程序的功能是输出的前20项,按每行5个数的形式输出。

Fibonacci数列:F1=1,F2=1,Fn=Fn-1+Fn-2(n>=2)

Dim a As Integer, b As Integer

Dim c As Integer, i As Integer

a = 1:

b = 1: i = 3

Print a, b,

Do While (i <= 20)

c = a + b

a = b

b = c

【1 】

If 【2 】Then

Print

End If

【3 】

Loop

End Sub

4.执行下面的程序段后,s的值为____________。

a=5

For i=2.6 To 4.9 Step 0.6

s=s+1

Next i

5.下面是一个体操评分程序。20位评委,除去一个最高分和一个最低分,计算平均分(设满分为10分)。

Max=0

Min=10

For i=1 To 20

n=Val(InputBox"请输入分数")

If ______________Then Max=n

If ______________Then Min=n

s=s+n

Next i

s=______________

p=s/18

Print"最高分";Max,"最低分";Min

Print"最后得分:";p

6.下面程序的功能是求1到100的平方和,如果平方和超过了1000则跳出循环,输出此时的和S。

For I=1 To 100

If s>1000 Then

______________

End If

next i

abc:Print s

7.以下程序段的输出结果是____________

num=0

While num<=2

num=num+1

Print num

Wend

8.以下程序段的输出结果是____________

Dim j As Integer,s As Integer

Do

s=s+j

Loop Until j=5

Print "s=";s

四、程序阅读题

1.写出下面程序的运行结果。

Private Sub Form_Click()

s=1

For m=1 To 3

For n=m To 3

For k=n To m Step -1

s=s*k

Next k,n,m

Print s

End Sub

2.写出下面程序的运行结果。

Private Sub Form_Click()

Print Spc(10-i);

For j=1 To 2*i-1

Print "*";

Next j

Print

Next i

End Sub

4.写出下面程序的运行结果。Private Sub Form_Click()

m=0

Do

m=m+1

If m>10 Then Exit Do

Loop Until m<10

Print m

End Sub

5.写出下面程序的运行结果。Private Sub Form_Click() Array Dim m As Integer,n As Integer

m=10

Do

m=m+n

For n=10 To m step -1

m=m+n

Next n

Loop While m<50

Print m;n

End Sub

18.下列程序的输出结果是________。Dim y As Integer

y=10

While y<>0

y=y-1

Wend

Print "y=" ; y

A) y=0 B) y=1 C) y=随机值D) y=-1

19.以下程序的输出结果是________。

Dim m As Integer

m=1

While m<=3

m=m+1

Print m;

Wend

A) 2 B) 2 3 C) 2 3 4 D) 2 3 4 5

20.下面的程序运行结果是________。

Private Sub Form_Click()

m=0

Do Until 0

m=m+1

If m>10 Then Exit Do

Loop

Print m

End Sub

1.下列过程的功能是:在对多个文本框进行输入时,对第一个文本框(Text1)输入完毕后用回车键使焦点跳到第二个文本框(Text2),而不是Tab键来切换。请完成该程序。Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)

If 【1 】Then

Text2. 【2 】

End If

End Sub

1.编写如下两个事件过程:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

Print Chr(KeyCode)

End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)

Print Chr(KeyAscii)

End Sub

在一般情况下(即不按住Shift键和锁定大写),运行程序,如果按A键,则程序的输出结果是什么?

2.在窗体上画一个命令按钮和一个文本框,并把窗体的KeyPreview属性设置为True,然后编写如下代码:

Dim saveall As String

Private Sub Command1_Click()

Text1.Text = UCase(saveall)

End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)

saveall = saveall + Chr(KeyAscii)

End Sub

Private Sub Form_Load()

Text1.Text = ""

End Sub

程序运行后,在键盘上输入abcdefg,单击命令按钮,写出文本框上显示的内容。

3.单击窗体时,下列程序的执行结果为________。

Private Sub Form_Click()

Test (2)

End Sub

Private Sub Test(x As Integer)

x = x * 2 + 1

If x < 6 Then

Call Test(x)

End If

x = x * 2 + 1

Print x;

End Sub

6.单击窗体时,下列程序代码的执行结果为________,如果在Procl过程的第二形参y前加ByVal关键字,那么单击窗体时,程序代码的执行结果为________。

Private Sub Form_Click()

Dim x As Integer, y As Integer, z As Integer

x = 1: y = 2: z = 3

Call procl(x, x, z)

Call procl(x, y, y)

End Sub

Private Sub procl(x As Integer, y As Integer, z As Integer)

x = 3 * z

y = 2 * z

z = x + y

Print x; y; z

End Sub

9.下列程序连续运行三次的结果为________。

Option Explicit

Sub First()

Static s As Integer

Dim i As Integer

For i = 1 To 10 Step 2

s = s + i

Next i

Print s;

End Sub

Private Sub Command1_Click()

Dim a As Integer, b As Integer, c As Integer

Call First

End Sub

10.运行下列程序,在立即窗口上第二行显示________;第三行显示________。

Option Explicit

Private Sub Command1_Click()

Dim b As Integer

Dim d As Integer

a = 1:

b = 2

d = fun(a, fun(a, b))

Debug.Print a, b, d

End Sub

Private Function fun(k As Integer, n As Integer)

As Integer

Debug.Print k, n;

k = n + a + k

n = k + a + n

fun = k + n

Debug.Print fun

End Function

三、程序阅读题:

3.写出下列程序的执行结果。

Option Explicit

Sub Ss(ByVal x As Integer, ByRef y As Integer, z As Integer)

x = x + 1

y = y + 1

z = z + 1

End Sub

Private Sub Command1_Click()

Dim a As Integer, b As Integer, c As Integer

a = 1:

b = 2:

c = 3

Call Ss(a, b, c)

Print a, b, c

End Sub

4.在窗体上画一个命令按钮,名称为Command1,程序运行后,写出下面程序的输出结果。

M=IIf(x>y,x,y)

End Function

Private Sub Command1_Click()

Dim a As Integer,b As Integer

a=100

b=200

print M(a,b)

End Sub

5.写出下面程序的输出结果。

Private Sub Command1_Click()

Dim k As Integer

For i=3 To 5 Step 2

k=i

Call text(k)

m=m+k

Next i

Print m;i

End Sub

Private Sub test(n As Integer)

n=1+2*n

End Sub

6.写出下面程序的输出结果。

Function F(a As Integer)

b=0

Static c

b=b+1

c=c+1

F=a+b+c

End Function

Private Sub Command1_Click()

a=2

For i=1 To 3

Print F(a)

Next i

End Sub

End Sub

9.当发生了Command1_Click事件后,

写出下面程序的输出结果。

Dim k As Integer

If n=1 Then

k=1

Else

k=2*age(n-1)+3

End If

age=k

End Function

Private Sub Command1_Click()

Dim a As Integer,k As Integer

k=5 : a=age(5) : Print a

End Sub

四、程序填空题:

3.以下Function过程Odd用于判断一个数是否为奇数。当单击命令按钮时,随机产生一个二位数,设用Odd过程判断该数是否是奇数。如果是奇数,则显示True,否则显示False。Option Explicit

Private Sub Command1_Click()

Dim x As Integer

x = 【1 】

Print x, Odd(x)

End Sub

Function Odd(ByVal n As Integer) As Boolean

If 【2 】Then

Odd = False

Else

Odd = True

End If

End Function

4.下列程序的功能是求两个正整数的最大公约数。阅读下列程序,请在空格处天如相应的语句,使之完成上述功能。

Option Explicit

Private Sub Command1_Click()

Dim a As Integer, b As Integer, g As Integer

a = InputBox("输入数字a:")

b = InputBox("输入数字b:")

【1 】= Gc(a, b)

Print a; "和"; b; "的最大公约数是:"; g

End Sub

Private Function Gc(ByVal x As Integer, 【2 】As Integer)

Dim z As Integer

z = x Mod y

Do While z <> 0

x = y

y = z

z = x Mod y

Loop

Gc = 【3 】

End Function

5.下列程序的功能是将一个数的各位数字相乘并打印在窗体上。阅读下列程序,请在空格处天如相应的语句,使之完成上述功能。

Option Explicit

Private Sub Command1_Click()

Dim n As Long

n = InputBox("请输入一个数")

Print Fun1(n)

相关文档