Using Procedures and Exception Handling MCQs

Chapter 8: Using Procedures and Exception Handling

MULTIPLE CHOICE

  1. A ____ screen can be added to engage the user while the application is loading.

a.

startup

c.

title

b.

flash

d.

splash

ANS:  D                    PTS:   1                    REF:   554

  1. The ____ property allows you to change the generic graphic on the splash screen.

a.

BackGround

c.

BackgroundImage

b.

BackImage

d.

BackGroundPicture

ANS:  C                    PTS:   1                    REF:   555

  1. The Project Designer provides a central location for managing project ____.

a.

properties

c.

resources

b.

settings

d.

all of the above

ANS:  D                    PTS:   1                    REF:   557

  1. The Project ____ appears as a single window in the Visual Studio IDE.

a.

Manager

c.

Designer

b.

Control

d.

Application

ANS:  C                    PTS:   1                    REF:   557

  1. The ____ Information dialog box contains values that include the program title, description, company, product, and copyright date.

a.

Assembly

c.

Activity

b.

ActiveX

d.

Argument

ANS:  A                    PTS:   1                    REF:   558

  1. Using the ____ procedure will cause the application to wait a specific amount of time.

a.

Stop

c.

Wait

b.

Pause

d.

Sleep

ANS:  D                    PTS:   1                    REF:   560

  1. The ____ procedure pauses the execution of an application for a specified duration of time.

a.

Suspend

c.

Pause

b.

Sleep

d.

Halt

ANS:  B                    PTS:   1                    REF:   560

  1. The ____ prefix is used when naming a ComboBox object like the one in the accompanying figure.

a.

cmb

c.

cbx

b.

cbo

d.

cmo

ANS:  B                    PTS:   1                    REF:   562

  1. If the user selects the first item in a ComboBox like the one in the accompanying figure, the SelectedIndex property will have the value ____.

a.

-1

c.

1

b.

0

d.

2

ANS:  B                    PTS:   1                    REF:   564

  1. When the selected index of a ComboBox is equal to ____, it indicates that the first item in the ComboBox list was selected.

a.

-1

c.

1

b.

0

d.

null

ANS:  B                    PTS:   1                    REF:   564

  1. The ____ event of a ComboBox object is triggered when the user changes the selection.

a.

SelectedIndex

c.

SelectedIndexChanged

b.

IndexChanged

d.

ChangedSelectedIndex

ANS:  C                    PTS:   1                    REF:   566

  1. The ____ event is triggered when the selection of a ComboBox object is changed.

a.

SelectedIndexChanged

c.

NewSelection

b.

SelectionAdjusted

d.

NewIndex

ANS:  A                    PTS:   1                    REF:   566

  1. A(n) ____ is a named set of code that is executed only when called.

a.

parameter

c.

argument

b.

procedure

d.

index

ANS:  B                    PTS:   1                    REF:   567

  1. To execute code in a procedure, a procedure ____ must be made.

a.

invocation

c.

call

b.

cast

d.

metric

ANS:  C                    PTS:   1                    REF:   567

  1. A ____ procedure completes its task but does not return any data to the calling procedure.

a.

Private

c.

Function

b.

Sub

d.

Public

ANS:  B                    PTS:   1                    REF:   567

  1. A Sub procedure can return ____ value(s) to the calling procedure

a.

0

c.

2

b.

1

d.

3

ANS:  A                    PTS:   1                    REF:   567

  1. If the third item in a ComboBox list is selected by the user, the SelectedIndex property of the ComboBox will have the value ____.

a.

1

c.

3

b.

2

d.

4

ANS:  B                    PTS:   1                    REF:   569

  1. Arguments are contained inside ____ after the name of the procedure to be called.

a.

braces

c.

brackets

b.

parentheses

d.

quotation marks

ANS:  B                    PTS:   1                    REF:   570

  1. A(n) ____ is a value that is passed to a procedure when the procedure is called.

a.

parameter

c.

index

b.

sub

d.

argument

ANS:  D                    PTS:   1                    REF:   570

  1. An argument that is passed ____ will send only the value of the passed argument.

a.

ByRef

c.

ByVal

b.

ByHand

d.

ByVar

ANS:  C                    PTS:   1                    REF:   571

  1. An argument that is passed ____ allows the procedure to modify the contents of the variable being passed.

a.

ByRef

c.

ByVal

b.

ByHand

d.

ByVar

ANS:  A                    PTS:   1                    REF:   573

  1. A ____ procedure completes its task and returns a value of a specified data type.

a.

Form

c.

Function

b.

Sub

d.

Splash

ANS:  C                    PTS:   1                    REF:   575

  1. A Sub procedure ____ argument(s).

a.

cannot accept any

c.

can accept two

b.

can accept one

d.

can accept any number of

ANS:  D                    PTS:   1                    REF:   575

  1. A Function procedure can pass back ____ value(s) using the Return statement to the calling procedure.

a.

0

c.

2

b.

1

d.

3

ANS:  B                    PTS:   1                    REF:   576

  1. The keyword ____ is used in a Function procedure to return a single value.

a.

SendVal

c.

ReturnVal

b.

Return

d.

ReturnValue

ANS:  B                    PTS:   1                    REF:   576

  1. A ____ procedure can return only one value back to the calling procedure.

a.

Value

c.

Return

b.

Sub

d.

Function

ANS:  D                    PTS:   1                    REF:   576

  1. The ____ keyword is used in a Function procedure to send a single value back to the call procedure.

a.

Return

c.

Send

b.

Sub

d.

Deliver

ANS:  A                    PTS:   1                    REF:   576

  1. A variable declared as Private at the ____ level can be accessed by procedures and events within the class but not by any code outside of the class.

a.

block

c.

global

b.

local

d.

class

ANS:  D                    PTS:   1                    REF:   578

  1. To return multiple variables from a Function procedure, arguments passed ____ must be used.

a.

ByVal

c.

ByRef

b.

BySub

d.

ByArg

ANS:  C                    PTS:   1                    REF:   578

  1. To detect exceptions and take corrective action, the ____ structure is used.

a.

Try-Catch

c.

Catch-Error

b.

Try-Code

d.

Try-CatchError

ANS:  A                    PTS:   1                    REF:   579

  1. The ____ keyword is placed before the Sub keyword when creating a Sub procedure to specify that the procedure can be called only by code within the class in which it exists.

a.

Contained

c.

Inner

b.

Private

d.

Distinct

ANS:  B                    PTS:   1                    REF:   579

  1. The ____ exception type occurs when a variable with no value is passed to a procedure.

a.

NullReferenceException

c.

OverflowException

b.

ArgumentNullException

d.

SystemException

ANS:  B                    PTS:   1                    REF:   580

  1. The ____ exception type occurs when a value is divided by zero.

a.

DivisionError

c.

DivideByZeroException

b.

ZeroError

d.

ZeroDivisionError

ANS:  C                    PTS:   1                    REF:   580

  1. The ____ exception type occurs when a variable is converted to another data type that is not possible.

a.

TypeException

c.

FormatMismatchException

b.

TypeMismatchException

d.

FormatException

ANS:  D                    PTS:   1                    REF:   580

  1. The ____ exception type occurs when a value exceeds its assigned data type.

a.

NullReferenceException

c.

OverflowException

b.

ArgumentNullException

d.

SystemException

ANS:  C                    PTS:   1                    REF:   580

  1. The ____ exception type is used to catch all generic exceptions within a Try-Catch structure.

a.

NullReferenceException

c.

OverflowException

b.

ArgumentNullException

d.

SystemException

ANS:  D                    PTS:   1                    REF:   580

  1. The keyword(s) ____ is/are used to specify the termination of a Try-Catch block of code.

a.

Terminate

c.

End Try

b.

Conclude

d.

Quit Catch

ANS:  C                    PTS:   1                    REF:   580

  1. The ____ exception type occurs when a procedure is called and the result is not possible.

a.

NullReferenceException

c.

OverflowException

b.

ArgumentNullException

d.

SystemException

ANS:  A                    PTS:   1                    REF:   580

  1. A Try-Catch structure ____ Catch blocks of code.

a.

cannot contain any

c.

can contain two

b.

can contain one

d.

can contain any number of

ANS:  D                    PTS:   1                    REF:   581

  1. In a Try-Catch structure, the ____ keyword precedes code that will always execute regardless of whether any exception occurred.

a.

Else

c.

Catch

b.

Finally

d.

Next

ANS:  B                    PTS:   1                    REF:   582

MULTIPLE RESPONSE

Modified Multiple Choice

  1. The Project Designer contains fields to enter ____.

a.

program title

c.

file version

b.

company name

d.

Sub procedure

ANS:  A, B, C           PTS:   1                    REF:   558

  1. The ____ object can trigger a SelectedIndexChanged event when a selection is made.

a.

ComboBox

c.

SelectionBox

b.

DropDownList

d.

ListBox

ANS:  A, B, D           PTS:   1                    REF:   566

  1. ____ procedures are a kind of procedure provided by Visual Basic.

a.

Integrated

c.

Sub

b.

Master

d.

Function

ANS:  C, D               PTS:   1                    REF:   567

  1. A Sub procedure is called with a statement consisting of ____.

a.

the title of the program

c.

the master variable

b.

the procedure name

d.

a set of parentheses

ANS:  B, D               PTS:   1                    REF:   567

  1. ____ is an exception type that can be handled by a Try-Catch block.

a.

TextException

c.

OverflowException

b.

DivideByZeroException

d.

FormatException

ANS:  B, C, D           PTS:   1                    REF:   580

MODIFIED TRUE/FALSE

  1. To make what is shown in the accompanying figure display for a certain period of time, the Suspend procedure is placed in the form load event handler. _________________________

ANS:  F, Sleep

PTS:   1                    REF:   560

  1. A splash screen like the one in the accompanying figure can be used to make a program appear to load faster than it actually does. _________________________

ANS:  T                                                     PTS:   1                    REF:   561

  1. IntelliSense cannot be used to add a Sleep procedure to the program code. _________________________

ANS:  F, can

PTS:   1                    REF:   561

  1. Instructions to the user can be placed in the GUI property of a ComboBox. _________________________

ANS:  F, Text

PTS:   1                    REF:   563

  1. The Elements property of a ComboBox contains the choices available to the ComboBox. _________________________

ANS:  F, Items

PTS:   1                    REF:   563

TRUE/FALSE

  1. The SelectedItem property of a ComboBox returns an integer indicating which choice is currently selected.

ANS:  F                    PTS:   1                    REF:   564

  1. When the SelectedIndex property of a ComboBox has the value of 0, it indicates that no selection was made by the user.

ANS:  F                    PTS:   1                    REF:   565

  1. The keywords End SubProcedure signifies the end of a Sub procedure.

ANS:  F                    PTS:   1                    REF:   567

  1. Sub procedures are automatically executed when events such as the user clicking a button occur.

ANS:  F                    PTS:   1                    REF:   567

  1. A Sub procedure does not return any data to the calling procedure.

ANS:  T                    PTS:   1                    REF:   567

  1. A dollar sign ($) as the first character in a variable means it is a class variable that can be referenced in any procedure within the class.

ANS:  F                    PTS:   1                    REF:   569

  1. When a procedure call is completed, the program returns to the calling procedure and continues execution as normal.

ANS:  T                    PTS:   1                    REF:   569

  1. You specify you want to pass a value by reference by entering the keyword ByRef in the Sub procedure declaration.

ANS:  T                    PTS:   1                    REF:   573

  1. If a variable is passed ByVal and the value of its argument is changed, the initial variable will change as well.

ANS:  F                    PTS:   1                    REF:   573

  1. When you pass a variable as an argument that was declared with the ByVal keyword in a procedure, that procedure cannot change the original value of the variable.

ANS:  T                    PTS:   1                    REF:   574

  1. You can pass at most two arguments to a Sub procedure.

ANS:  F                    PTS:   1                    REF:   575

  1. If a Sub procedure has more than one argument, the variables are passed in the same order in which they appear in the procedure call statement.

ANS:  T                    PTS:   1                    REF:   575

  1. The Private keyword is required in a Function procedure declaration.

ANS:  F                    PTS:   1                    REF:   575

  1. You cannot exclude the receiving variable in the procedure call.

ANS:  F                    PTS:   1                    REF:   575

  1. A Function procedure returns a single value to the calling procedure.

ANS:  T                    PTS:   1                    REF:   575

  1. A Function procedure call can be used anywhere that a variable of the same data type could be used.

ANS:  T                    PTS:   1                    REF:   575

  1. The statement End Procedure is used to signify the end of a Function declaration.

ANS:  F                    PTS:   1                    REF:   575

  1. A Function procedure declaration must define what type of data it will return when it is called.

ANS:  T                    PTS:   1                    REF:   575

  1. A Function procedure can pass many values back to the calling procedure.

ANS:  F                    PTS:   1                    REF:   576

  1. In a Function procedure declaration, any lines of code after a Return statement will not be executed.

ANS:  T                    PTS:   1                    REF:   576

  1. If the code in the Try section of a Try-Catch structure generates an error, the program will not be terminated when the exception occurs.

ANS:  T                    PTS:   1                    REF:   580

  1. A DivideByZeroException occurs when a value is divided by zero.

ANS:  T                    PTS:   1                    REF:   580

  1. Only six different types of exceptions can occur in a Visual Basic program.

ANS:  F                    PTS:   1                    REF:   580

  1. If an exception occurs in the Try section of a Try-Catch structure and there is no matching Catch block, the program will stop.

ANS:  T                    PTS:   1                    REF:   581

  1. A Finally statement is required after each Catch block in a Try-Catch structure to execute any necessary clean-up code.

ANS:  F                    PTS:   1                    REF:   582

COMPLETION

  1. An opening screen that appears as an application is loading is called a(n) ____________________ screen.

ANS:  splash

PTS:   1                    REF:   554

  1. The ____________________ property is used to display a graphic on a splash screen.

ANS:  BackgroundImage

PTS:   1                    REF:   555

  1. A(n) ____________________ object allows a user to enter text and also select from predefined options in a list.

ANS:  ComboBox

PTS:   1                    REF:   562

  1. The ____________________ property of a ComboBox is an integer value identifying which choice in the list portion is currently selected.

ANS:  SelectedIndex

PTS:   1                    REF:   564

  1. The ____________________ property is used to return the string value of the selected choice in a ComboBox.

ANS:  SelectedItem

PTS:   1                    REF:   564

  1. A(n) ____________________ procedure is a procedure that performs a task but does not return any data.

ANS:  Sub

PTS:   1                    REF:   567

  1. When an argument is declared in a procedure with the keyword ____________________, it means that the procedure has access to the value of the passed argument, but cannot change the actual variable that is passed in as the argument.

ANS:  ByVal

PTS:   1                    REF:   571

  1. Passing an argument ____________________ guarantees that the original value of the variable in the calling procedure is not affected.

ANS: 

ByVal

by value

PTS:   1                    REF:   573

  1. Passing an argument ____________________ allows the procedure to modify the contents of the variable that is being passed.

ANS: 

ByRef

by reference

PTS:   1                    REF:   573

  1. A(n) ____________________ procedure is used when data needs to be returned to the calling procedure.

ANS:  Function

PTS:   1                    REF:   575

  1. The ____________________ data type in the Function declaration specifies the type of data type that will be passed back to the calling procedure.

ANS:  return

PTS:   1                    REF:   575

  1. The ____________________ code structure traps errors in code that may generate an exception.

ANS: 

Try-Catch

Try Catch

PTS:   1                    REF:   579

  1. In a Try-Catch structure, the ____________________ keyword indicates the start of code that could cause an exception to occur.

ANS:  Try

PTS:   1                    REF:   579

  1. In a Try-Catch structure, the ____________________ keyword indicates code for handling an exception.

ANS:  Catch

PTS:   1                    REF:   579

  1. The ____________________ exception type occurs when a variable with no value is passed to a procedure.

ANS:  ArgumentNullException

PTS:   1                    REF:   580

  1. The ____________________ exception type occurs when a procedure is called and the result is not possible.

ANS:  NullReferenceException

PTS:   1                    REF:   580

  1. The ____________________ exception type occurs when a value exceeds the size limit of its assigned data type.

ANS:  OverflowException

PTS:   1                    REF:   580

  1. The ____________________ is a generic exception that occurs whenever an error occurs that does not have an exception defined for it.

ANS:  SystemException

PTS:   1                    REF:   580

  1. The ____________________ exception type occurs when a variable is converted to another type that is not possible.

ANS:  FormatException

PTS:   1                    REF:   580

  1. The ____________________ exception type occurs when attempting to divide a value by zero.

ANS:  DivideByZeroException

PTS:   1                    REF:   580

MATCHING

Identify the letter of the choice that best matches the phrase or definition.

a.

template

f.

ListBox

b.

Project Designer

g.

Sub procedure

c.

SelectedIndex

h.

Private

d.

SelectedIndexChanged

i.

procedure call

e.

procedure

j.

Select Case

  1. Using this event handler of a ComboBox is more efficient for the user because the user does not need to click elsewhere to indicate that a choice has been made
  1. Consists of the procedure name followed by a set of parentheses
  1. Visual Basic provides a generic one of these in order to use a splash screen with a project
  1. If a selection has not been made, this property of a ComboBox object will be -1
  1. A Sub procedure may be used within this kind of statement
  1. This provides a central location for managing project properties, settings, and resources
  1. Object that can trigger a SelectedIndexChanged event when a selection is made
  1. If a Sub procedure is declared with this keyword, it can only be accessed by code within the class in which it was declared
  1. Must be explicitly called from within the program code
  1. This helps to make code easier to manage code
  1. ANS:  D                    PTS:   1                    REF:   566
  1. ANS:  I                     PTS:   1                    REF:   567
  1. ANS:  A                    PTS:   1                    REF:   555
  1. ANS:  C                    PTS:   1                    REF:   565
  1. ANS:  J                     PTS:   1                    REF:   569
  1. ANS:  B                    PTS:   1                    REF:   557
  1. ANS:  F                    PTS:   1                    REF:   566
  1. ANS:  H                    PTS:   1                    REF:   567
  1. ANS:  G                    PTS:   1                    REF:   567
  1. ANS:  E                    PTS:   1                    REF:   552

ESSAY

  1. Explain what a Sub procedure is and how it is coded, making sure to define the term procedure call in your response.

ANS: 

A Sub procedure is a procedure that completes its task but does not return any data to the calling procedure. A Sub procedure in Visual Basic 2010 is defined by using the Sub keyword. A Sub procedure is the series of Visual Basic statements enclosed by the Sub and End Sub statements. Each time the Sub procedure is called, its statements are executed, starting with the first executable statement after the Sub statement and ending with the first End Sub statement. A Sub procedure is called with a statement consisting of the procedure name and a set of parentheses in the form of a procedure call.

PTS:   1                    REF:   567                TOP:   Critical Thinking      

  1. How is a Function procedure similar to or different from a Sub procedure?

ANS: 

A Function procedure is similar to a Sub procedure except that a Function procedure returns a single value to the calling procedure. Just like a Sub procedure, you can pass variables to the Function procedure using ByVal and ByRef. A Function procedure uses the keyword Function (instead of the keyword Sub) in the procedure declaration. You also must specify a return data type in the procedure declaration to define the type of variable that is being returned to the calling procedure by the Function procedure.

PTS:   1                    REF:   575                TOP:   Critical Thinking      

  1. It is true that multiple Catch blocks can be defined for a single Try block where each Catch block will catch a particular class of exception. When is this useful? Discuss best practices in coding multiple Catch blocks in this instance, and walk through an explanation of how these multiple Catch blocks function in the flow of the program.

ANS: 

This is useful when you want to state which type of error occurred, identifying to users the particular mistake that was made. It is best to order exceptions in Catch blocks from the most specific to the least specific. In other words, place the Catch block that is most likely to be needed for the most common exception first in a series of Catch statements. If an exception occurs during the execution of the Try block, Visual Basic examines each Catch statement within the Try-Catch block until it finds one whose condition matches that error. If a match is found, control transfers to the first line of code in the Catch block. If no matching Catch statement is found, the search proceeds to the next Catch statement in the Try-Catch block. This process continues through the entire code block until a matching Catch block is found in the current procedure. If no match is found, an exception that stops the program is produced.

PTS:   1                    REF:   581                TOP:   Critical Thinking      

CASE

Critical Thinking Questions

Case 8-1

Of all of the concepts Sheila has learned so far, she is having the hardest time understanding the use of procedures, including when and how to use them. She asks her instructor for some additional clarification.

  1. Which of the following is not a true statement her instructor makes to Sheila?

a. The Sub procedure should perform a single, defined task.

c. A Function procedure must perform reasonably substantial processing.

b. Procedures that perform multiple tasks tend to become large and difficult to design and code.

d. It is good practice to place a procedure call statement in a calling procedure and have the called procedure contain one or two program statements.

ANS: 

D.

PTS:   1                    REF:   585                TOP:   Critical Thinking      

  1. Sheila is having trouble even deciding whether or not to place a set of programming steps in a Sub procedure or a Function procedure, so her instructor tells her to ask herself a series of questions to make that decision. Which one of the following is NOT a question that the instructor suggests that she ask herself?

a. Will the program be easier to read if the code is placed in a separate procedure?

c. Does this task require more than eight or nine programming statements?

b. Does the proposed code perform a single task?

d. Can the Sub procedure or Function procedure perform its processing by receiving data as arguments, and by returning data either using the Return statement or by using ByRef arguments?

ANS: 

C.

PTS:   1                    REF:   585                TOP:   Critical Thinking      

Critical Thinking Questions

Case 8-2

Your colleague hasn’t used Visual Basic in a while and so when he encounters a decision point, he sometimes calls out to you over the cubicle wall to get answers to his questions.

  1. He wants help remembering which method of passing an argument will give the Sub procedure access to the value of the passed argument without actually referencing the variable declared in the calling procedure. Which of the following do you suggest to him?

a. ByVal

c. ByArg

b. ByRef

d. ByInd

ANS: 

A.

PTS:   1                    REF:   571                TOP:   Critical Thinking      

  1. After a few minutes, he calls back out. This time, he wants to know how to pass a reference to a value instead of passing the value itself. Before suggesting that he begin to use his reference texts or a search engine on the Web to find his own answers, you instead suggest which of the following to him?

a. ByVal

c. ByArg

b. ByRef

d. ByInd

ANS: 

B.

PTS:   1                    REF:   573                TOP:   Critical Thinking      

hihi


Want latest solution of this assignment

Want to order fresh copy of the Sample Template Answers? online or do you need the old solutions for Sample Template, contact our customer support or talk to us to get the answers of it.