第五章 过程:本章介绍了在Visual Basic中通用过程的分类,子过程和函数过程的定义及调用,变量和过程的作用域。5.1过程的概念:介绍Visual Basic中过程的概念,通用过程的分类。
5.2子过程的定义和调用:介绍在Visual Basic中子过程的定义和调用方法。
5.3函数过程的定义和调用:介绍在Visual Basic中函数过程的定义和调用方法。
5.4参数传递:介绍在Visual Basic中过程的参数传递方式。
5.5过程的嵌套和递归调用:介绍在Visual Basic中如何进行过程的嵌套调用和递归调用。
5.6变量的作用域:介绍在Visual Basic中变量的作用域及使用。
5.7过程的作用域:介绍在Visual Basic中过程的作用域分类及使用。
[单选题]下面程序的运行结果为(   )。Dim a%, b%, c%Sub p1(x%, y%)    Dim c As Integer    x = 2 * x: y = y + 2: c = x + yEnd SubSub p2(x%, ByVal y%)    Dim c As Integer    x = 2 * x: y = y + 2: c = x + yEnd SubPrivate Sub Command1_Click()    a = 2: b = 4: c = 6    Call p1(a, b)    Call p2(a, b)    Print a; b; cEnd Sub

选项:[ 8  6  6,  4  6  6,  8  8  6,  4  6  10]
[单选题]以下是一个能返回数组a中最大数的函数过程代码: 

Function maxval(a() As Integer) As Integer   

Dim max%   

max = 1 

For i = 2 To 10 

If a(i) > a(max) Then max = i   

Next i 

     maxval = max 

End Function 

Private Sub Command1_Click()

    Dim x(1 To 10) As Integer

    For i = 1 To 10

        x(i) = Int(Rnd() * 100)

        Print x(i);

    Next i

    Print

    Print maxval(x())

End Sub程序运行时,发现函数过程的返回值是错的需要修改,下面的修改方案中正确的是(  )。 

选项:[语句“For i = 2 To 10”应改为“For i = 1 To 10”, 语句“max = 1”应改为“max = a(1)” , 语句“maxval = max ”应改为“maxval  = a(max)”, If语句“max = i”应改为“max = a(i)”]
[单选题]下列叙述中正确的是(   )。

选项:[在某个Sub过程中定义的局部变量可以与其他事件过程中定义的局部变量同名,但其作用域只限于该过程, 在调用过程时,所有局部变量被系统初始化为0或空字符串, 局部变量的作用域可以超出所定义的过程, 在窗体的Form_Load事件中定义的变量是全局变量]
[单选题]有如下函数过程:Function Cys(ByVal x As Integer, ByVal y As Integer) As Integer    Dim quotients    Do While y <> 0        quotients = x / y        x = y        y = quotients    Loop    Cys = xEnd Function以下是调用该函数的事件过程,该程序的运行结果是(   )。Private Sub Command1_Click()    Dim a As Integer    Dim b As Integer    a = 10    b = 2    x = Cys(a, b)    Print xEnd Sub

选项:[100, 25, 5, 0]
[单选题]假定有以下函数过程: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 = s1End Function在窗体上添加一个命令按钮,然后编写如下事件过程:Private Sub Command1_Click()    Dim Str1 As String    Dim Str2 As String    Str1 = InputBox("请输入一个字符串")    Str2 = Fun(Str1)    Print Str2End Sub程序运行后,单击命令按钮,如果在输入对话框中输入字符串“abcdefg”,则单击“确定”按钮后再窗体上输出的结果为(   )。

选项:[Abcdefg, gfedcba, ABCDEFG, GFEDCBA]
[单选题]若已编写了一个Sort子过程,在该工程中有多个窗体,为了方便地调用Sort子过程,应将该过程放在  (   )中。

选项:[类模块, 窗体模块, 标准模块, 工程]
[单选题] 在窗体上画一个命令按钮(名称为Command1),并编写如下代码:Function Fun1(ByVal a As Integer, b As Integer) As Integer    Dim t As Integer    t = a - b    b = t + a    Fun1 = t + bEnd Function Private Sub Command1_Click()    Dim x As Integer    x = 10    Print Fun1(Fun1(x, (Fun1(x, x - 1))), x - 1)End Sub程序运行后,单击命令按钮,输出结果是(  )。

选项:[ 10,  11,  0,  21]
[单选题]有如下函数过程:Function secproc(x As Integer, y As Integer, z As Integer)    secproc = 3 * y + z + 2 * xEnd Function Private Sub Command1_Click()    Dim a As Integer, b As Integer, c As Integer    a = 2: b = 3: c = 4    Print secproc(c, b, a)End Sub该程序的运行结果是(   )。

选项:[20, 18, 19, 17]
[单选题]假定有如下的Sub过程:Sub fun(x As Single, y As Single)    t = x    x = t / y    y = t Mod yEnd Sub在窗体上画一个命令按钮,然后编写如下事件过程:Private Sub Command1_Click()    Dim a As Single    Dim b As Single    a = 6    b = 4    fun a, b    Print a, bEnd Sub程序运行后,单击命令按钮,输出结果为(   )。

选项:[5  4, 1  1, 1.5  2, 1.25  4]
[单选题]下面程序:Function a(x)    Static b As Integer    b = b + x ^ 2    Print bEnd Function Private Sub Command1_Click()    Dim c%    c = a(2)End Sub单击两次命令按钮,第二次显示的结果是(   )。

选项:[ 2,  8,  4,  6]

温馨提示支付 ¥1.00 元后可查看付费内容,请先翻页预览!
点赞(0) dxwkbang
返回
顶部