文档库 最新最全的文档下载
当前位置:文档库 › 第八章VB过程

第八章VB过程

第八章VB过程
第八章VB过程

第八章VB过程

一、选择题

1. 下列叙述中不正确的是:

A、VB中的函数功能类似于Sub过程

B、Sub过程不可以递归

C、子过程不返回与其特定子过程名相关联的值

D、过程是没有返回值的函数,又常被称为Sub过程,在事件过程或其他

子过程中可以按名称调用过程

2. 在过程定义中,Private表示:

A、此过程可以被其他过程调用

B、此过程不可以被任何其他过程调用

C、此过程只可以被本工程中的其他过程调用

D、此过程只可以被本窗体模块中的其他过程调用

3. 以下说法错误的是:

A、函数过程没有返回值

B、子过程没有返回值

C、函数过程可以带参数

D、子过程可以带参数

4. 下列哪条语句是错的_______。

A、exit sub

B、exit function

C、exit while

D、exit do

5. 以下关于过程及过程参数的描述中,错误的是:

A、过程的参数可以是控件名称

B、用数组作为过程的参数时,使用的是“传地址”方式

C、只有函数过程能够将过程中处理的信息传回到调用的程序中

D、窗体可以作为过程的参数

6. 不能脱离控件(包括客体) 而独立存在的过程是:

A、事件过程

B、通用过程

C、 Sub过程

D、函数过程

7. 在Visual Basic中传递参数的方法有_________方式。

A、一种

B、两种

C、三种

D、四种

8. 关键字声明的局部变量在整个程序运行中一直存在

A、Dim

B、Public

C、Static

D、Private

9. 在Visual Basic应用程序中,以下正确的描述是:

A、过程的定义可以嵌套,但过程的调用不能嵌套

B、过程的定义不可以嵌套,但过程的调用可以嵌套

C、过程的定义和过程的调用均可以嵌套

D、过程的定义和过程的调用均不能嵌套

10. 在窗体中添加一个命令按钮(Name属性为Command1),然后编写如下代码:

Private Sub Command1_Click()

x = InputBox("请输入整数")

a = f1(Val(x))

Print a

End Sub

运行程序后,如果单击命令按钮,则显示一个输入对话框,在该对话框中输入一个整数,并用这个整数作为实参调用函数过程f1。在f1中判断所输入的整数是否是奇数,如果是奇数,过程f1返回1,否则返回0。

能够正确实现上述功能的代码是:

A、Function f1(ByRef b As Integer)

B、Function f1(ByRef b As Integer)

If b Mod 2 = 0 Then If b Mod 2 = 0 Then

return 0 f1=0

Else Else

return 1 f1=1

End If End If

End Function End Function

C、Function f1(ByRef b As Integer)

D、f1(ByRef b As Integer)

If b Mod 2 = 0 Then If b Mod 2 = 0 Then f1=1 return 0

Else Else

f1=0 return 1

End If End If

End Function End Function

11. 在窗体中添加一个命令按钮,然后编写如下代码:

Function func(a As Integer, b As Integer) As Integer

Static m As Integer, i As Integer

m = 0

i = 2

i = i + m + 1

m = i + a + b

func = m

End Function

Private Sub Command1_Click()

Dim k As Integer, m As Integer

Dim p As Integer

k = 4

m = 1

p = func(k, m)

Print p;

p = func(k, m)

Print p

End Sub

程序运行后,单击命令按钮,输出结果为:

A、8 17

B、8 16

C、8 20

D、8 8

12. Sub过程与Function过程最根本的区别是:

A、 Sub过程可以用Call语句直接使用过程名调用,而Function过程不可以

B、 Function过程可以有形参,Sub过程不可以

C、 Sub过程不能返回值,而Function过程能返回值

D、两种过程参数的传递方式不同

13. 设有如下代码:

Private Sub Form_Load()

Show

Dim b() As Variant

b = Array(1, 3, 5, 7, 9, 11, 13, 15)

Call search(b)

For i = 0 To 7

Print b(i)

Next i

End Sub

此程序的功能是通过过程调用,把数组中的元素按逆序存放。为实现此功能,缺少的过程的程序段是:

A、Private Sub search(dim a() as Variant )

Dim T

For i = LBound(a) To UBound(a)

T = a(i): a(i) = a(UBound(a) - i): a(UBound(a) - i) = T

Next i

End Sub

B、Private Sub search(dim a() as Variant )

Dim T

Dim J As Integer

J = (LBound(a) + UBound(a)) / 2

For i = LBound(a) To J

T = a(i): a(i) = a(UBound(a) - i): a(UBound(a) - i) = T Next i

End Sub

C、Private Sub search(a() As Variant)

Dim T

For i = LBound(a) To UBound(a)

T = a(i): a(i) = a(UBound(a) - i): a(UBound(a) - i) = T Next i

End Sub

D、Private Sub search(a() As Variant)

Dim T

Dim J As Integer

J = (LBound(a) + UBound(a)) / 2

For i = LBound(a) To J

T = a(i): a(i) = a(UBound(a) - i): a(UBound(a) - i) = T Next i

End Sub

14. 假定有以下两个过程:

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

Dim t As Integer

t = x

x = y

y = t

End Sub

Sub S2(x As Integer, y As Integer)

Dim t As Integer

t = x

x = y

y = t

End Sub

则以下说法中正确的是:

A、用过程S1可以实现交换两个变量值的操作,S2不能实现

B、用过程S2可以实现交换两个变量值的操作,S1不能实现

C、用过程S1和S2都可以实现交换两个变量值的操作

D、用过程S1和S2都不能实现交换两个变量值的操作

15. 单击命令按钮时,下列程序的执行结果为:

Private Sub Command1_Click()

Dim x As Integer, y As Integer

x=12: y=32

Call PCS(x, y)

Print x; y

End Sub

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

n=n - 10

m=m - 10

End Sub

A、 12 32

B、 2 32

C、 2 3

D、 12 3

16. 在窗体上画一个名称为Comamnd1的命令按钮,然后编写如下通用过程和命令按钮的事件过程:

Private Function fun(ByVal m As Integer)

If m Mod 2 = 0 Then

fun = 2

Else

fun = 1

End If

End Function

Private Sub Command1_Click()

Dim i As Integer, s As Integer

s = 0

For i = 1 To 5

s = s + fun(i)

Next

Print s

End Sub

程序运行后,单击命令按钮,则窗体上显示的是:

A、6

B、7

C、8

D、9

17. 假定有如下的Sub过程:

Sub S(x As Single,y As Single)

t=x

x=t/y

y=t Mod y

End Sub

在窗体上画一个命令按钮,然后编写如下事件过程:

Private Sub Command1_Click()

Dim a As Single

Dim b As Single

a=5

b=4

S a,b

Print a,b

End Sub

程序运行后,单击命令按钮,输出结果为:

A、5 4

B、1 l

C、1.25 4

D、1.25 l

18. 设一个工程由两个窗体组成,其名称分别为Form1和Form2,在Form1上有一个名称为Command1的命令按钮。窗体Form1的程序代码如下:Private Sub Command1_Click()

Dim a As Integer

a =10

Call g(Form2,a)

End Sub

Private Sub g(f As Form,x As Integer)

y=IIf(x>10,100,-100)

f.Show

f.Caption=y

End Sub

运行以上程序,正确的结果是:

A、Form1的Caption属性值为100

B、Form2的Caption属性值为-100

C、Form1的Caption属性值为-100

D、Form2的Caption属性值为100

19. 在窗体上画一个命令按钮,然后编写如下程序:

Private Sub Command1_Click()

Dim a As Integer, b As Integer

a=1

b=2

Print N(a, b)

End Sub

Function N(x As Integer, y As Integer) As Integer

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

End Function

程序运行后,单击命令按钮,输出结果为:

A、 1

B、 2

C、 5

D、 8

20. 单击命令按钮时,下列程序的执行结果为:

Private Sub Command1_Click()

Dim x As Integer, y As Integer

x=50: y=78

Call PPP(x, y)

Print x; y

End Sub

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

n=n \ 10

m=m\ 10

End Sub

A、 0 8

B、 50 78

C、 4 50

D、 78 50

21. 阅读程序:

Sub subP(b() As Integer

For i =1 To 4

b(i)=2*i

Next i

End Sub

Private Sub Commandl_Click()

Dim a(1 To 4)As Integer

a (1)=5

a (2)=6

a (3)=7

a (4)=8

subP a ()

For i =1 To 4

Print a(i)

Next i

End Sub

运行上面的程序,单击命令按钮,输出结果为:

A、2

B、5

C、10

D、出错

4 6 12

6 7 14

8 8 16

22. 单击命令按钮时,下列程序的执行结果为:

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、 12 32

B、 2 32

C、 2 3

D、 12 3

23. 设有如下通用过程:

Public Sub fun(a() As Integer, x As Integer)

For i = 1 To 5

x = x + a(i)

Next

End Sub

在窗体上画一个名称为Text1的文本框和一个名称为Command1的命令按钮,然后编写如下事件过程:

Private Sub Command1_Click()

Dim arr(5) As Integer, n As Integer

For i = 1 To 5

arr(i) = i + i

Next

fun arr, n

Text1.Text = Str(n)

End Sub

程序运行后,单击命令按钮,则在文本框中显示的内容是:

A、30

B、25

C、20

D、15

24. 在窗体上画一个名称为Commandl的命令按钮,再画两个名称分别为Labell、Label2的标签,然后编写如下程序代码:

Private x As Integer

Private Sub Command1_Click()

X=5:Y=3

Call proc(x,Y)

Labell.Caption=X

Label2.Caption=Y

End Sub

Private Sub proc(ByVal a As Integer,ByVal b As Integer)

X=a* a

Y=b+b

End Sub

程序运行后,单击命令按钮,则两个标签中显示的内容分别是:

A、5和3

B、25和3

C、25和6

D、5和6

25. 阅读程序:

Function F(a As Integer)

b=0

Static c

b=b+l

c=c+l

F=a+b+c

End Function

Private Sub Command1_Click()

Dim a As Integer

a=2

For i=1 To 3

Print F(a);

Next i

End Sub

运行上面的程序,单击命令按钮,输出结果为:

A、4 4 4

B、4 5 6

C、4 6 8

D、4 7 9

26. 在窗体上画一个名称为Command1的命令按钮,然后编写如下通用过程和命令按钮的事件过程:

Private Function f(m As Integer)

If m Mod 2=0 Then

f=m

Else

f=l

End If

End Function

Private Sub Command1_Click()

Dim i As Integer

s=0

For i=l TO 5

s=s+f(i)

Next

Print s

End Sub

程序运行后,单击命令按钮,在窗体上显示的是:

A、ll

B、10

C、9

D、8

27. 有如下的程序:

Private Sub Form_Click()

Dim a As Integer, b As Integer

a= 8

b= 3

Call test(6 ,a ,b+1)

Print "主程序";6;a; b

End Sub

Sub test (x As Integer, y As Integer, z As Integer)

Print "子程序";x;y;z

x = 2

y = 4

z = 9

End Sub

当运行程序后,显示的结果是:

A)子程序6 4 3 B)主程序6 4 3 C)主程序6 8 4 D)子程序6 8 4

主程序6 8 4 子程序6 8 4 子程序6 4 3 主程序6 4 3 28. 在窗体中添加一个命令按钮、一个标签和一个文本框,并将文本框的Text属性置空,编写命令按钮Command1的Click事件代码:

Private Function fun(x As Long) As Boolean

If x Mod 2 = 0 Then

fun = True

Else

fun = False

End If

End Function

Private Sub Command1_Click()

Dim n As Long

n = Val(text1.Text)

p = IIf(fun(n), "偶数", "奇数")

Lable1.Caption = n & "是一个" & p

End Sub

程序运行后,在文本框中输入20,单击命令按钮后,标签中的内容为:

A、20是一个奇数

B、20

C、20是一个偶数

D、2

29. 设有如下过程:

Sub ff(x,y,z,)

x=y+z

End Sub

以下所有参数的虚实结合都是传址方式的调用语句是:

A、 Call ff(5,7,z)

B、 Call ff(x,y,z)

C、 Call ff(3+x,5+y,z)

D、 Call ff(x+y,x-y,z)

30. 在窗体上画一个名称为Command1的命令按钮和一个名称为Text1的文本框,然后编写如下程序:

Private Sub Command1 Click()

Dim x,y,z As Integer

x=5

y=7

z=0

Text1.Text=""

Call P1(x,y,z)

Text1.Text=Str(z)

End Sub

Sub P1(ByVal a As Integer,ByVal b As Integer,c As Integer) c=a+b

End Sub

程序运行后,如果单击命令按钮,则在文本框中显示的内容是:

A、0

B、12

C、Str(z)

D、没有显示

31. 定义过程的格式中Static关键字的作用是指定过程中的局部变量在内存中的存储方式。若使用了Static关键字,则:

A、每次调用此过程,该过程中的局部变量都会被重新初始化

B、在本过程中使用到的,在其他过程中定义的变量也为Statci型

C、每次调用此过程时,该过程中的局部变量的值保持在上一次调用后的值

D、定义了该过程中定义的局部变量为“自动”变量

32. 下列关于过程叙述不正确的是:

A、过程的传值调用是将实参的具体值传值递给形参

B、过程的传址调用是将实参在内存的地址传递给形参

C、过程的传值调用参数是单向传递的,过程的传址调用参数是双向传递的

D、无论过程传值调用还是过程传址调用,参数传递都是双向的

33. 下列叙述中正确的是:

A、在窗体的Form-Load事件过程中定义的变量是全局变量

B、局部变量的作用域可以超出所定义的过程

C、在某个Sub过程中定义的局部变量可以与其它事件过程中定义的局部变量同名,但其作用域只限于该过程

D、在调用过程中,所有局部变量被系统初始化为0或空字符串

34. 在窗体上画一个名称为Command1的命令按钮,编写如下程序:

Private Sub Command1_Click()

Print pl(3,7)

End Sub

Public Function pl(x As Single,n As Integer) As Single If n=0 Then

pl=1

Else

If n Mod 2=1 Then

pl=x*x+n

Else

P1=x*x-n

End If

End If

End Function

程序运行后,单击该命令按钮,屏幕上显示的结果是:

A、2

B、1

C、0

D、16

35. 假定有以下函数过程:

Function Fun(S As String) As String

Dim s1 As String

For i=1 To Len(S)

s1=UCase(Mid(S,i,1))+s1

Next i

Fun=s1

End Function

在窗体上画一个命令按钮,然后编写如下事件过程:

Prlvate Sub Commmldl_Click()

Dim Str1 As String,Str2 As String

Strl=inputbox(”请输入一个字符串”)

Str2=Fun(Strl)

Print Str2

End Sub

程序运行后,单击命令按钮,如果在输入对话框中输入字符串

“abcdefg”,则单击“确定”按钮后在窗体上的输出结果为:

A、abcdefg

B、ABCDEFG

C、gfedcba

D、GFEDCBA

36. 以下叙述不正确的是:

A、在Sub过程中可以调用Function过程

B、在用Call调用Sub过程时必须把参数放在括号里

C、在Sub过程中可以嵌套定义Function

D、用Static声明的过程中的局部变量都是Static类型

37. 在窗体上画一个命令按钮,其名称为Command1,然后编写如下程序:

Function Func(ByVal x As Integer,y As Integer)

y=x*y

If y>0 Then

Func=x

Else

Func=y

End If

End Function

Private Sub Command1_Click()

Dim a As Integer, b As Integer

a=3

b=4

c=Func(a,b)

Print"a=";a,

Print"b=":b,

Print"c=":c

End Sub

程序运行后,单击命令按钮,其输出结果为:

A、a=3 b=12 c=3

B、a=3 b=4 c=3

C、a=3 b=4 c=12

D、a=13 b=12 c=12

38. 一个工程中包含两个名称分别为Forml、Form2的窗体,一个名称为mdlFunc的标准

模块。假定在Forml、Form2和mdlFunc中分别建立了自定义过程,其定义格式为:

Forml中定义的过程:

PriVate Sub frmfunctionl()

End Sub

Form2中定义的过程:

Public Sub frmffunction2()

End Sub

mdlFunc中定义的过程:

PubliC Sub mdlFunction()

End Sub

在调用上述过程的程序中,如果不指明窗体或模块的名称,则以下叙述中正确的是:

A、上述三个过程都可以在工程中的任何窗体或模块中被调用

B、frmfunction2和mdlfunction过程能够在工程中各个窗体或模块中被调用

C、上述三个过程都只能在各自被定义的模块中调用

D、只有mdlFunction过程能够被工程中各个窗体或模块调用

39. 下面程序段,运行后的结果是:

Private Sub Command1_Click()

Dim b%(1 To 4) , i%, t#

For i=1 To 4

b(i) =i

Next i

t=Tof(b() )

Print "t="; t,

End Sub

Function Tof(a() As Integer)

Dim t#, i%

t=1

For i=2 To UBound(A)

t=t * a(i)

Next i

Tof=t

End Function

A、 t=18

B、 t=24

C、 t=30

D、 t=32

40. 下列程序的执行结果为:

Private Sub Command1_Click()

Dim s1 As String, s2 As String

s1="abcdef"

Call Invert(s1, s2)

Print s2

End Sub

Private Sub Invert(ByVal xstr As String, ystr As String)

Dim tempstr As String

i=Len(xstr)

Do While i >=1

tempstr=tempstr + Mid(xstr, i, 1)

i=i - 1

Loop

ystr=tempstr

End Sub

A、 fedcba

B、 abcdef

C、afbecd

D、 defabc。

41. 设有如下程序

Option Base 1

Private Sub Command1_Click()

Dim a(10) As Integer

Dim n As Integer

n=InputBox("输入数据")

If n<10 Then

Call GetArray(a,n)

End If

End Sub

Private Sub GetArray(b() As Integer,n As Integer) Dim c(10) As Integer

j=0

For i=1 To n

b(i)=CInt(Rnd()*100)

If b(i)/2=b(i)\2 Then

j=j+1

c(j)=b(i)

End If

Next

Print j

End Sub

以下叙述中错误的是:

A、数组b中的偶数被保存在数组c中

B、程序运行结束后,在窗体上显示的是c数组中元素的个数

C、GetArray过程的参数n是按值传送的

D、如果输入的数据大于10,则窗体上不显示任何显示

42. 下列程序的执行结果为:

Private Sub Command1_Click()

Dim x As Integer, y As Integer

x=12: y=20

Call Value(x, y)

Print x; y

End Sub

Private Sub Value(ByVal m As Integer, ByVal n As Integer)

m=m * 2: n=n - 5

Print m; n

End Sub

A、 20 12

B、 12 20

C、 24 15

D、 24 12

20 15 12 25 12 20 12 15 43. 单击命令按钮时,下列程序的运行结果为:

Private Sub Command1_Click()

Print MyFund(20, 18)

End Sub

Public Function MyFund(m As Integer, n As Integer) As Integer Do While m <> n

Do While m > n: m=m - n: Loop

Do While m < n: n=n - m: Loop

Loop

MyFund=m

End Function

A、 0

B、 2

C、 4

D、 6

44. 单击按钮时,以下程序运行后的输出结果是:

Private Sub proc1(x As Integer, y As Integer, z As Integer) x=3 * z

y=2 * z

z=x + y

End Sub

Private Sub Command1_Click()

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

x=1: y=2: z=3

Call proc1(x, x, z)

Print x; x; z

Call proc1(x, y, y)

Print x; y; y

End Sub

A、6 6 12

B、9 5 10

C、 9 6 12

D、 9 10 10

6 10 10 5 10 10 9 10 15 5 4 10 45. 单击一次命令按钮后,下列程序的执行结果是:

Private Sub Command1_Click()

s=P(1) + P(2) + P(3) + P(4)

Print s

End Sub

Public Function P(N As Integer)

Static Sum

For i=1 To N

Sum=Sum + i

Next i

P=Sum

End Function

A、 15

B、 25

C、35

D、 45

46. 在窗体上画一个命令按钮,然后编写下列程序:

Private Sub Command1_Click()

Tcl 2

Tcl 3

Tcl 4

End Sub

Sub Tcl(a As Integer)

Static x As Integer

x=x + a

Print x;

End Sub

程序运行后,单击命令按钮,输出结果为:

A、 2 3 4

B、 2 5 9

C、 3 5 4

D、 2 4 3

47. 阅读下列程序:

Private Sub Command1_Click()

Dim i As Integer, k As Integer

k=2

For i=1 To 3

Print H(k) ;

Next i

End Sub

Function H(j As Integer)

a=0

Static b

a=a + 1

b=b + 1

H=a*b + j

End Function

程序运行后,单击命令按钮输出结果是:

A、 2 3 4

B、 3 4 5

C、 5 6 7

D、 3 5 6

48. 窗体上有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

Private 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内的值分别是:

A、2 4

2 4

B、2 4

4 8

C、10 10

58 58

D、4 4

8 8

49. 单击命令按钮时,下列程序的执行结果是:

Private Sub Command1_Click()

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

a=3

b=4

c=5

Print SecProc(c, b, a)

End Sub

Function FirProc(x As Integer, y As Integer, z As Integer) FirProc=2*x+y+3*z

End Function

Function SecProc(x As Integer, y As Integer, z As Integer) SecProc=FirProc(z, x, y) +x

End Function

A、 20

B、 22

C、 28

D、 30

50. 在窗体中添加一个命令按钮,然后编写如下代码:

Sub sub1(k As Integer, s As Integer)

s = 1

For m = 1 To k

s = s * m

Next m

End Sub

Private Sub Command1_Click()

Dim k As Integer, s As Integer

total = 0

For k = 2 To 4

Call sub1(k, s)

total = total + s

Next k

Print total

End Sub

程序运行后,单击命令按钮,输出结果为:

A、9

B、32

C、6

D、8

51. 下列程序的执行结果为:

Private Sub Command1_Click()

Dim FirStr As String

FirStr = "abcdef"

Print Pat(FirStr)

End Sub

Private Function Pat(xStr As String) As String

Dim tempStr As String, strLen As Integer

tempStr = ""

strLen = Len(xStr)

i = 1

Do While i <= Len(xStr) - 3

tempStr = tempStr + Mid(xStr, i, 1) + Mid(xStr, strLen - i + 1, 1)

i = i + 1

Loop

Pat = tempStr

End Function

A、 abcdef

B、 afbecd

C、 fedcba

D、 defabc

52. 如下程序,运行的结果是:

Private Sub Form_Click()

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

For i= 0 to 4

x(i)=i + 1

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

A、3 4 7 5 6

B、3 5 7 4 5

C、2 3 4 4 5

D、4 5 6 7 8

53. 在窗体上设置相应的控件,并在代码窗口编写下列程序:

Private Sub Form_Click()

相关文档