Site hosted by Angelfire.com: Build your free website today!


 

Name:

Date:

Quiz Three / Visual Basic II

General Questions

Questions (1) and (2) pertain to the code sample directly below this line.

    Private Sub Swap(ByRef strLeft As String, ByRef strRight As String)
        Dim strSomePlace As String

        strSomePlace = strLeft
        strLeft = strRight
        strRight = strSomePlace
    End Sub

(1) The "Swap" method, shown above, is declared "Private."  In Visual Basic, what effect does declaring "Swap" to be "Private" have on the scope of "Swap"?

(A) None at all.

(B) "Swap" cannot be directly accessed by other methods of the same class.

(C) "Swap" cannot be directly accessed by the methods of other classes.

(D) "Swap" can be accessed anywhere within the program provided the code from which it is referenced is surrounded by a "WITH" and "END WITH" statement.

(2) What is the most likely reason the author of "Swap" declared "strLeft" and "strRight" as "ByRef"?

(A) Just a matter of style.

(B) To make the question more tricky.

(C) To save memory.

(D) To allow the caller to swap the values of variables defined outside of the "Swap" method.

For Loop Questions

Questions (3) and (4) pertain to the code sample directly below this line.


    Private Sub Reverse(ByRef strArray() As String)
        Dim intLength As Integer
        Dim intMiddleIndex As Integer
        Dim intIndex As Integer

        intLength = strArray.Length

        If (intLength <= 0) Then
            Return
        End If

        intMiddleIndex = intLength / 2

        For intIndex = 0 To intMiddleIndex - 1
            Swap(strArray(intIndex), strArray(intLength - 1 - intIndex))
        Next
    End Sub

(3) If the array strArray is {"10", "FOOD", "SILLY"}, how many times does "Swap" get called within the loop?

(A) Three times.

(B) One time.

(C) Zero times.

(D) Two times.

(4) What is the value of "intIndex" the first time through the loop?

(1) 0

(2) 1

(3) 2

(4) 3

Do Loop Questions

Questions (5) and (6) pertain to the code sample directly below this line.

    Private Function FindSmallest(ByRef strValues() As String) As String
        Dim intIndex As Integer
        Dim intElements As Integer = strValues.Length
        Dim strSomething As String

        If intElements > 0 Then
            strSomething = strValues(0)
            intIndex = 1
            Do While intIndex < intElements
                If CInt(strValues(intIndex)) < CInt(strSomething) Then
                    strSomething = strValues(intIndex)
                End If
                intIndex = intIndex + 1
            Loop
            Return strSomething
        Else
            Return ""
        End If
    End Function

(5) If the array strValues = {"10", "5", "7", "11"}, how many times during a single call to "FindSmallest" does the condition "intIndex < intElements" get evaluated?

(A) 1

(B) 2

(C) 3

(D) 4

(6) We could have used a "For" loop instead of a "While" loop.

(A) True

(B) False

Bonus Question

(7) Write three lines of code which will pop up a message box seven times.  Write the lines of code next to (A), (B) and (C) in the code sample below:

Private Sub Foo()
Dim intCount As Integer

(A)

(B)

(C)

End Sub