Deck 6: Procedures and Functions
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/31
Play
Full screen (f)
Deck 6: Procedures and Functions
1
When a procedure finishes execution, .
A) control returns to the point where the procedure was called and continues with the next statement
B) the application terminates unless the procedure contains a Return statement
C) control transfers to the next procedure found in the code
D) the application waits for the user to trigger the next event
A) control returns to the point where the procedure was called and continues with the next statement
B) the application terminates unless the procedure contains a Return statement
C) control transfers to the next procedure found in the code
D) the application waits for the user to trigger the next event
A
2
Which of the following calls to the GetNumber procedure is not valid? Sub GetNumberByVal intNumber as Integer)
' procedure body)
End Sub
A) GetNumberintX)
B) GetNumber3 + 5 * 8 + intX)
C) GetNumberintX + 3, intY)
D) GetNumberCInttxtNumber.Text))
' procedure body)
End Sub
A) GetNumberintX)
B) GetNumber3 + 5 * 8 + intX)
C) GetNumberintX + 3, intY)
D) GetNumberCInttxtNumber.Text))
C
3
By writing your own procedures, you can _an applications code, that is, break it into small, manageable procedures.
A) streamline
B) duplicate
C) modularize
D) functionalize
A) streamline
B) duplicate
C) modularize
D) functionalize
C
4
A procedure may not be accessed by procedures from another class or form if the _access specifier is used.
A) Private
B) Public
C) Static
D) Scope
A) Private
B) Public
C) Static
D) Scope
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
5
In the context of Visual Basic procedures and functions, what is an argument?
A) A value received by a procedure from the caller
B) A value passed to a procedure by the caller.
C) A local variable that retains its value between procedure calls.
D) A disagreement between the procedure and the statement that calls it.
A) A value received by a procedure from the caller
B) A value passed to a procedure by the caller.
C) A local variable that retains its value between procedure calls.
D) A disagreement between the procedure and the statement that calls it.
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
6
A is a special variable that receives a value being passed into a procedure or function.
A) temporary variable
B) pseudo-constant
C) class-level variable
D) parameter
A) temporary variable
B) pseudo-constant
C) class-level variable
D) parameter
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
7
Which of the following functions accepts a parameter named dblSales and returns the commission to the calling statement? Assume that the commission should equal the sales multiplied by the commission rate. Use the following table as a guide to the calculation of the commission rate. 

Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
8
Which of the following code examples is a function that will accept three integer parameters, calculate their average, and return the result?
A) Function AverageByVal intX As Integer, ByVal intY As Integer, _ ByVal intZ As Integer) As Single
Average = intX + intY + intZ) / 3
End Function
B) Function AverageByVal intX As Integer, ByVal intY as Integer, _ ByVal intZ As Integer) As Single
Average = intX + intY + intZ / 3
Return Average
End Function
C) Function AverageByRef intX As Integer, ByRef intY as Integer, _ ByRef intZ As Integer, ByRef Average As Double)
Average = intX + intY + intZ) / 3
End Function
D) Function AverageByVal intX As Integer, ByVal IntY as Integer, _ ByVal intZ As Integer) As Single
Return intX + intY + intZ) / 3
End Function
A) Function AverageByVal intX As Integer, ByVal intY As Integer, _ ByVal intZ As Integer) As Single
Average = intX + intY + intZ) / 3
End Function
B) Function AverageByVal intX As Integer, ByVal intY as Integer, _ ByVal intZ As Integer) As Single
Average = intX + intY + intZ / 3
Return Average
End Function
C) Function AverageByRef intX As Integer, ByRef intY as Integer, _ ByRef intZ As Integer, ByRef Average As Double)
Average = intX + intY + intZ) / 3
End Function
D) Function AverageByVal intX As Integer, ByVal IntY as Integer, _ ByVal intZ As Integer) As Single
Return intX + intY + intZ) / 3
End Function
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
9
When calling a procedure, passed arguments and declared parameters must agree in all of the following ways except .
A) the order of arguments and parameters must correspond
B) the names of the arguments and parameters must correspond
C) the types of the arguments and parameters must correspond
D) the number of arguments and the number of parameters must be the same
A) the order of arguments and parameters must correspond
B) the names of the arguments and parameters must correspond
C) the types of the arguments and parameters must correspond
D) the number of arguments and the number of parameters must be the same
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
10
What is incorrect about the following function? Function sumByVal intX As Integer, ByVal intY As Integer) As Integer
Dim intAns As Integer
IntAns = intX + intY
End Function
A) intAns should not be declared inside the Function.
B) the as Integer at the end of the Function heading should be eliminated.
C) the function does not return a value
D) parameters intA and intB should be declared as ByRef
Dim intAns As Integer
IntAns = intX + intY
End Function
A) intAns should not be declared inside the Function.
B) the as Integer at the end of the Function heading should be eliminated.
C) the function does not return a value
D) parameters intA and intB should be declared as ByRef
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
11
When a parameter is declared using the _qualifier, the procedure has access to the original argument variable and may make changes to its value.
A) ByValue
B) ByAddress
C) ByRef
D) ByDefault
A) ByValue
B) ByAddress
C) ByRef
D) ByDefault
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
12
What is assigned to lblDisplay.Text when the following code executes? Dim intNumber As Integer = 4
AddOneintNumber, 6)
LblDisplay.Text = intNumber
' Code for AddOne
Public Sub AddOneByVal intFirst As Integer, ByVal intSecond As Integer)
IntFirst += 1
IntSecond += 1
End Sub
A) 4
B) 5
C) 6
D) 7
AddOneintNumber, 6)
LblDisplay.Text = intNumber
' Code for AddOne
Public Sub AddOneByVal intFirst As Integer, ByVal intSecond As Integer)
IntFirst += 1
IntSecond += 1
End Sub
A) 4
B) 5
C) 6
D) 7
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
13
Which of the following does not apply to procedures and functions?
A) they help to break up a large body of code into smaller chunks
B) they make it easier to maintain and modify code
C) the execution time is significantly reduced by calling procedures and functions
D) they permit the same sequence of code statements to be called from multiple places
A) they help to break up a large body of code into smaller chunks
B) they make it easier to maintain and modify code
C) the execution time is significantly reduced by calling procedures and functions
D) they permit the same sequence of code statements to be called from multiple places
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
14
Which of the following examples correctly uses an input box to assign a value to an integer, and returns the integer to the calling program using a reference parameter?
A) Sub GetInputByVal intNumber As Integer) intNumber = CIntInputBox"Enter an Integer"))
End Sub
B) Sub GetInputByRef intNumber As Integer) intNumber = CIntInputBox"Enter an Integer"))
End Sub
C) Sub GetInputByRef intNumber As Integer) intNumber = CIntInputBox"Enter an Integer"))
Return intNumber
End Sub
D) Sub GetInput) Dim intNumber As Integer
IntNumber = CIntInputBox"Enter an Integer"))
End Sub
A) Sub GetInputByVal intNumber As Integer) intNumber = CIntInputBox"Enter an Integer"))
End Sub
B) Sub GetInputByRef intNumber As Integer) intNumber = CIntInputBox"Enter an Integer"))
End Sub
C) Sub GetInputByRef intNumber As Integer) intNumber = CIntInputBox"Enter an Integer"))
Return intNumber
End Sub
D) Sub GetInput) Dim intNumber As Integer
IntNumber = CIntInputBox"Enter an Integer"))
End Sub
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
15
Which of the following procedures will keep track of the number of times it was called?
A) Private Sub KeepTrackByVal intCount As Integer) intCount += 1
End Sub
B) Private Sub KeepTrack) Dim intCount As Integer
IntCount += 1
End Sub
C) Private Sub KeepTrack) Static intCount As Integer
IntCount += 1
End Sub
D) Private Sub KeepTrack) Public intCount As Integer
IntCount += 1
End Sub
A) Private Sub KeepTrackByVal intCount As Integer) intCount += 1
End Sub
B) Private Sub KeepTrack) Dim intCount As Integer
IntCount += 1
End Sub
C) Private Sub KeepTrack) Static intCount As Integer
IntCount += 1
End Sub
D) Private Sub KeepTrack) Public intCount As Integer
IntCount += 1
End Sub
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
16
All of the following are true about functions except .
A) you can use a function call in an expression
B) they can return one or more values
C) they must contain at least one Return statement
D) you can assign the return value from a function to a variable
A) you can use a function call in an expression
B) they can return one or more values
C) they must contain at least one Return statement
D) you can assign the return value from a function to a variable
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
17
Which debugging command executes a function call without stepping through function's statements?
A) Step Into
B) Step Over
C) Step Out
D) Step All
A) Step Into
B) Step Over
C) Step Out
D) Step All
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
18
What is the value of intTotal after the following code executes? Dim intNumber1 As Integer = 2
Dim intNumber2 As Integer = 3
Dim intTotal As Integer
IntTotal = AddSquaresintNumber1, intNumber2)
Function AddSquaresByVal intA As Integer, ByVal intB As Integer) As Integer
IntA = intA * intA
IntB = intB * intB
Return intA + intB
IntA = 0
IntB = 0
End Function
A) 0
B) 5
C) 10
D) 13
Dim intNumber2 As Integer = 3
Dim intTotal As Integer
IntTotal = AddSquaresintNumber1, intNumber2)
Function AddSquaresByVal intA As Integer, ByVal intB As Integer) As Integer
IntA = intA * intA
IntB = intB * intB
Return intA + intB
IntA = 0
IntB = 0
End Function
A) 0
B) 5
C) 10
D) 13
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
19
True/False) When debugging a program in break mode, the Step Into command causes the currently highlighted line of code to execute.
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
20
Which statement is true in regard to passing an argument by value to a procedure?
A) A copy of the argument is passed to the procedure.
B) A reference to the argument is passed to the procedure.
C) The procedure has access to the original argument and can make changes to it.
D) A procedure's parameter list need not agree with the arguments provided to the procedure.
A) A copy of the argument is passed to the procedure.
B) A reference to the argument is passed to the procedure.
C) The procedure has access to the original argument and can make changes to it.
D) A procedure's parameter list need not agree with the arguments provided to the procedure.
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
21
Choose a new, more descriptive name for the WhatIsIt function based on the result of the code below. Function WhatIsItByVal intRepeat as Integer) as Integer
Dim intResult as Integer = 1
Dim intCount as Integer
For intCount = 1 to intRepeat
IntResult = intResult * 2
Next intCount
Return intResult
End Function
A) PowersOfTwo
B) SquareRootsOfTwo
C) MultiplyByTwo
D) TwoPlusTwo
Dim intResult as Integer = 1
Dim intCount as Integer
For intCount = 1 to intRepeat
IntResult = intResult * 2
Next intCount
Return intResult
End Function
A) PowersOfTwo
B) SquareRootsOfTwo
C) MultiplyByTwo
D) TwoPlusTwo
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
22
Which of the following procedure declarations matches the call to the IsLetter procedure below? Dim strText as String = txtInput.Text
Dim blnLetter as Boolean = IsLetterstrText)
A) Sub IsLetterByVal strInput as String) as Boolean
B) Sub IsLetterByVal blnResult as Boolean) as String
C) Function IsLetterByVal strInput as String) as Boolean
D) Function IsLetterByVal blnResult as Boolean) as String
Dim blnLetter as Boolean = IsLetterstrText)
A) Sub IsLetterByVal strInput as String) as Boolean
B) Sub IsLetterByVal blnResult as Boolean) as String
C) Function IsLetterByVal strInput as String) as Boolean
D) Function IsLetterByVal blnResult as Boolean) as String
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
23
What is the syntax error in the following procedure? Sub DisplayValueDim intNumber As Integer)
MessageBox.ShowintNumber.ToString))
End Sub
A) intNumber cannot be converted to a string
B) the procedure's does not have a return value
C) Dim is not valid when declaring parameters
D) all of the above are true
MessageBox.ShowintNumber.ToString))
End Sub
A) intNumber cannot be converted to a string
B) the procedure's does not have a return value
C) Dim is not valid when declaring parameters
D) all of the above are true
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
24
Which one of the following declarations uses Pascal casing for the procedure name?
A) Sub MyProcedure)
End Sub
B) Sub myprocedure)
End Sub
C) Sub my_procedure)
End Sub
D) Sub myProcedure)
End Sub
A) Sub MyProcedure)
End Sub
B) Sub myprocedure)
End Sub
C) Sub my_procedure)
End Sub
D) Sub myProcedure)
End Sub
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
25
True/False) Although you can omit the ByVal keyword in a parameter variable declaration, it is still a good idea to use it.
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
26
What is wrong with the following GetName procedure? Sub GetNameByVal strName As String)
StrName = InputBox"Enter your Name:")
End Sub
A) The procedure is missing a Return statement.
B) GetName is a reserved word and cannot be used as a name of a procedure.
C) strName will be modified, but all changes will be lost when the procedure ends.
D) The syntax for the call to InputBox is incorrect.
StrName = InputBox"Enter your Name:")
End Sub
A) The procedure is missing a Return statement.
B) GetName is a reserved word and cannot be used as a name of a procedure.
C) strName will be modified, but all changes will be lost when the procedure ends.
D) The syntax for the call to InputBox is incorrect.
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
27
Which statement is not true regarding functions?
A) A function is a self-contained set of statements that can receive input values.
B) Visual Basic has many built-in functions such as CSngtxtInput.Text)
C) A function can only return a single value.
D) The same function can return several data types including integer, string, or double
A) A function is a self-contained set of statements that can receive input values.
B) Visual Basic has many built-in functions such as CSngtxtInput.Text)
C) A function can only return a single value.
D) The same function can return several data types including integer, string, or double
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
28
What will be the value of dblSum after the button btnAdd is clicked, assuming that 25 is entered by the user into txtNum1, and 35 is entered into txtNum2? Private Sub btnAdd_ClickByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnAdd.Click
Dim dblNum1, dblNum2, dblSum As Double
DblNum1 = CDbltxtNum1.Text)
DblNum2 = CDbltxtNum2.Text)
DblSum = SumdblNum1, dblNum2)
LblSum.Text = dblSum.ToString)
End Sub
Function SumByVal dblNum1 As Double, ByVal dblNum2 As Double) as Double
Return dblNum1 + dblNum2
End Function
A) 60
B) 50
C) 0
D) 70
ByVal e As System.EventArgs) Handles btnAdd.Click
Dim dblNum1, dblNum2, dblSum As Double
DblNum1 = CDbltxtNum1.Text)
DblNum2 = CDbltxtNum2.Text)
DblSum = SumdblNum1, dblNum2)
LblSum.Text = dblSum.ToString)
End Sub
Function SumByVal dblNum1 As Double, ByVal dblNum2 As Double) as Double
Return dblNum1 + dblNum2
End Function
A) 60
B) 50
C) 0
D) 70
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
29
Which of the following can be returned by a function?
A) String values
B) Integer values
C) Boolean values
D) All of the above
A) String values
B) Integer values
C) Boolean values
D) All of the above
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
30
Which is the correct way to define a function named Square that receives an integer and returns an integer representing the square of the input value?
A) Function SquareByVal intNum as Integer) As Integer Return intNum * intNum
End Function
B) Function SquareByVal intNum as Integer) Return intNum * intNum
End Function
C) Function SquareByVal intNum as Integer) As Double Return intNum * intNum
End Function
D) Function SquareByVal intNum as Integer) As Double Dim dblAns as Double
DblAns = intNum * intNum
Return dblAns
End Function
A) Function SquareByVal intNum as Integer) As Integer Return intNum * intNum
End Function
B) Function SquareByVal intNum as Integer) Return intNum * intNum
End Function
C) Function SquareByVal intNum as Integer) As Double Return intNum * intNum
End Function
D) Function SquareByVal intNum as Integer) As Double Dim dblAns as Double
DblAns = intNum * intNum
Return dblAns
End Function
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
31
If you do not provide an access specifier for a procedure, it will be designated _by default.
A) Private
B) Protected
C) Friend
D) Public
A) Private
B) Protected
C) Friend
D) Public
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck