CIS Chapter 6
lblNewPrice.Text=GetNewPrice(dblCurrentPrice).ToString("C2")
The syntax _____ displays a return value. dblNewPrice = GetNewPrice(dblCurrentPrice) Dim dblNewPrice lblNewPrice.Text=GetNewPrice(dblCurrentPrice).ToString("C2") dblTotalDue = intQuantity*GetNewPrice(dblCurrentPrice)
dblNewPrice = GetNewPrice(dblCurrentPrice)
The syntax __________ assigns a return value to a variable. - lblNewPrice.Text = GetNewPrice(dblCurrentPrice.ToString - dblNewPrice = dblCurrentPrice - Dim dblNewPrice - dblNewPrice = GetNewPrice(dblCurrentPrice)
true
The types of the arguments must be in the same order as the types of the parameters
class scope
Variables declared globally but outside any procedure & can be used by any procedure on form
block scope
Variables declared inside blocks & can be used only inside that block
the function does not return a value
What is incorrect about the following function? Function sum (ByVal intX as Integer, ByVal intY as Integer) as Integer Dim intAns as Integer intAns = intX + intY End Function - The as Integer at the end of the Function heading should be eliminated - Parameters intA and intB should be declared as ByRef - intAns should not be declared inside the Function - The function does not return a value
strName will be modified, but all changes will be lost when the procedure ends
What is wrong with the following GetName procedure? Sub GetName (ByVal strName as String) strName = InputBox("Enter your Name:") End Sub - The syntax for the call to InputBox is incorrect - strName will be modified, but all changes will be lost when the procedure ends - GetName is a reserved word and cannot be used as a name of a procedure - The procedure is missing a Return statement
ByRef
When a parameter is declared using the ________ qualifier, the procedure has access to the original argument variable and may make changes to its value.
Function Square (ByVal intNum as Integer) as Integer Return intNum * intNum End Function
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? - Function Square (ByVal intNum as Integer) as Integer Return intNum * intNum End Function - Function Square (ByVal intNum as Integer) as Double Return intNum * intNum End Function - Function Square (ByVal intNum as Integer) Return intNum * intNum End Function - Function Square (ByVal intNum as Integer) as Double Dim dblAns as Double dblAns = intNum * intNum Return dbl Ans End Function
all of the above
Which of the following can be returned by a function? Integer values Boolean values String values All of the above
return dblNumber
Which of the following is a valid Return statement? - dblNumber Return - Return dblNumber ByRef - Return ByRef dblNumber - Return dblNumber
false
You can determine whether a variable is being passed by value or by reference by looking at the Call statement.
general format of a procedure declaration
[AccessSpecifier] Sub ProcedureName [(ParameterList]) (Statements) End Sub
procedure
a collection of statements that perform a task
function
a collection of statements that perform a task and then returns a value to the part of the program that exectued it
frame
a data structure that holds the values of all the local variables and formal parameters of a procedure
call stack
a last-in, first-out data structure that keeps track of calls to functions
argument
a value passed to a procedure
modularize an application's code, break it down into small managebale procdures, can reduce the amount of duplicated code
advantages of writing your own procedures
true
are event handlers examples of procedures
true
can declare multiple variables of the same name as long as they do not have the same scope
false, can only return one
can function procedures return more than one value?
loop counter variables
can only be used within the loop for which they are declared
true
cannot declare variables of the same name within the same block structure
ProcedureNameIsThis
example of pascal casing
step over
if you want to execute the line, but not single step through the function, what command should you use
step out
if you want to execute the remaining lines of the function and return to the line that called the function what command do you use
step into
if you want to single step through the procedure that is being called what command should you use
ParameterList
list of variables/values passed to the sub procedure
public
may also be accessed by procedures in other forms
true
mouse click is a type of procedure?
by value
only a copy of the argument is passed to the procedure
by reference
procedure has access to the original argument and can make changes to it
private
procedure may be accessed only by other procedures declared in the same class or form
local variables and formal parameters
procedure scope can only be used inside that procedure
locals window
shows all the local data (local variables and formal parameters) of the selected Procedure on the stack
parameter
special variable that receives a value being passed into a procedure
calling statement
statement that invokes a sub procedure
true
(t/f) Items are pushed onto the top of the stack and popped off the top of the stack
name, list of parameters, and return type
A function's signature consists of a...
true
sub procedure have no return type
modularity
take big task and break it into subtasks.
only as long as the procedure is executing
the formal parameters and local variables of a procedure exist
by value and by reference
two ways to pass arguments
method
used to mean both procedures and functions
ProcedureName
used to refer to the procedure
how to declare a function
AccessSpecifier] Function FunctionName ([ParameterList]) As DataType [Statements] Return value End Function
decTotal = decSubtotal + GetSalesTax(decSubtotal)
An application needs to calculate sales tax for purchases. You decide to simplify the code by putting the sales tax calculation in a function. The returned value from the function is then added to the Subtotal, and the result is stored in the decTotal variable. Which of the following statements will call the GetSalesTax function and return a vale to be used in the Total calculation? decTotal = decSubtotal + GetSalesTax(decSubtotal) decTotal = decSubtotal + GetSalesTax() decTotal = decSubtotal + GetSalesTax(decSubtotal As Decimal) decSubtotal + GetSalesTax(decSubtotal)
false
An event procedure is a Function procedure that is associated with a specific object and event.
parameters
An independent Sub procedure can contain one or more _______ in its procedure header that have procedure scope and store an item of data.
true
ByVal is optional and if omitted it is set as the default
as
The ________ keyword in a function header identifies the data type of the data being returned.