|
|
Name:Date:Quiz Three / Visual Basic IIGeneral Questions
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"?
(2) What is the most likely reason the author of "Swap" declared "strLeft" and "strRight" as "ByRef"?
For Loop Questions
(3) If the array strArray is {"10", "FOOD", "SILLY"}, how many times does "Swap" get called within the loop?
(4) What is the value of "intIndex" the first time through the loop?
Do Loop Questions
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? (6) We could have used a "For" loop instead of a "While" loop.
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() (A) (B) (C) End Sub |