Deck 3: Variables, Constants, and Calculations

Full screen (f)
exit full mode
Question
The Parse method and exception handling can be used to eliminate the problems encountered when the user does not enter a value into a field.
Use Space or
up arrow
down arrow
to flip the card.
Question
Variables that are declared in the Declarations section of a form module are available to all procedures in the form.
Question
Numeric constants may contain only the digits ( 0 - 9 ),a decimal point,and a sign ( + or - )at the left side.
Question
Assume that a variable is declared in the Declarations section of a form and named TOTAL_PAY_Decimal.This variable,TOTAL_PAY_Decimal,will be visible to all procedures in that form even though the programmer did not follow the naming conventions in the textbook and name the variable TotalPayDecimal.
Question
It is a good idea to set Option Strict On,in the Visual Basic environment in order to detect misspelled variable names when the project is run.
Question
GrandTotalDecimal is a valid variable name.
Question
Data whose value may not be changed during the execution of a project is referred to as a constant.
Question
A constant contains data whose value may be changed during the execution of a project.
Question
A variable named SalesTotalDecimal that is declared in the CalculateButton_Click event procedure can be used in any procedure of the form.
Question
When Option Explicit is turned on,you can use any variable name without first declaring it.
Question
A numeric variable that is declared with the Dim statement in a local procedure is initialized to zero each time the procedure is called.
Question
Constants can store string or numeric values.
Question
A variable that will store totals and that will be available to all procedures in the form must be declared as a constant.
Question
SCHOOL_NAME_String is in the correct format for a constant that holds the name of your school.
Question
If you are declaring a variable that will be used in calculations,you may use the string data type.
Question
When naming a constant,you should use uppercase characters in the name with an underscore between the words and the data type at the end of the name.
Question
Although it is best to always declare the data type on a Dim statement,the data type is optional.
Question
When using the format specifier codes,you can specify the number of digits to appear to the right of the decimal point.
Question
Variables that are declared inside a procedure can be used as counters and accumulators.(Ignore Static variables. )
Question
Calculations may be performed with variables.
Question
Which of the following is NOT a rule for naming identifiers for constants?

A)Include the data type at the end of the identifier.
B)Everything in the identifier's name should be capitalized except the data type.
C)Identifiers for constants should begin with a prefix of Const.
D)Identifiers for constants should use an underscore between words.
Question
A _______ variable is declared inside a procedure.

A)namespace
B)module-level
C)local
D)block
Question
Message boxes can be used to notify the user if input data is not a reasonable value.
Question
The data type that is used for decimal fractions is _______.

A)Decimal
B)Short
C)Integer
D)Fraction
Question
Which of the following is NOT a rule for naming identifiers?

A)Identifiers for constants should use an underscore between words.
B)Identifiers should use periods to separate words.
C)Identifiers should list the data type at the end of the name.
D)Identifiers cannot contain embedded blanks.
Question
When you declare a variable or a named constant,Visual Basic reserves an area of memory and assigns it a name called a(n)_______.

A)identifier
B)identity
C)declaration
D)dimension
Question
Message boxes can contain buttons.
Question
The reserved Visual Basic word,Dim,is short for dimension,which means _______.

A)declaration
B)size
C)storage location
D)identifier
Question
Where should the statement: Dim CounterInteger As Integer appear if you plan to use CounterInteger in only one event procedure?

A)The Declarations section of the form
B)The Form_Load procedure
C)The event procedure where CounterInteger will be used
D)The Namespace Constants file
Question
Intrinsic constants are _______.

A)declared using the keyword Const
B)declared using the keyword Dim
C)placed in the Declarations section of a form
D)built into Visual Studio
Question
Which of the following is a valid statement that can be used to declare a local variable that will store whole numbers?

A)Dim IndexWhole as Whole
B)Dim IndexString as String
C)Dim IntegerIndex as Index
D)Dim IndexInteger as Integer
Question
Variables declared within a button's click-event are _____ variables.

A)local
B)module-level
C)namespace
D)private
Question
Which of the following does not follow the conventions for naming identifiers?

A)UnitsEnrolledDecimal
B)ZipCodeString
C)Amount.Due.Decimal
D)COUNTRY_OF_BIRTH_String
Question
If Option Strict is turned off and a declaration statement does not specify a data type,it will default to _______.

A)boolean
B)string
C)object
D)variable
Question
Which of the following is NOT a valid rule for naming identifiers?

A)Names may contain underscores.
B)Names may contain letters.
C)Names may contain digits.
D)Names may contain spaces.
Question
Which of the following is NOT a valid Visual Basic data type?

A)Integer
B)Real
C)Decimal
D)String
Question
Where should the statement: Const ACCOUNT_NUMBER_String As String = "A45" appear if you plan to use ACCOUNT_NUMBER_String in more than one procedure?

A)The Declarations section of the form
B)The Form_Load procedure
C)The event procedure where ACCOUNT_NUMBER_String will be used
D)The Namespace Constants file
Question
The length of identifiers is limited to _______.

A)1 to 8 characters
B)1 to 256 characters
C)1 to 4,000 characters
D)1 to 16,383 characters
Question
Declaration statements _______.

A)can only be written inside a procedure
B)are only allowed in the Declarations section of a form
C)give variables and constants names,and specify the type of data they will hold
D)are not needed for constants
Question
Which of the following is a valid statement that can be used to declare a local variable that will store fractions?

A)Dim IndexFraction As Fraction
B)Dim IndexString As String
C)Dim IndexDecimal As Decimal
D)Dim IndexInteger As Integer
Question
To trap or catch exceptions,use a _______ block and enclose any statement(s)that might cause an error.

A)With \ End With
B)Try \ Catch
C)For \ Next
D)TheException
Question
Using the order of precedence and the formula below,what is AnswerInteger if?: NumberOneInteger = 2,NumberTwoInteger = 12,NumberThreeInteger = 20,and NumberFourInteger = 6
AnswerInteger = NumberOneInteger * (NumberTwoInteger + NumberThreeInteger)- NumberFourInteger / NumberOneInteger

A)19
B)41
C)61
D)None of these
Question
If a procedure contains a Dim statement and NameString is assigned as the identifier,NameString can be used _______.

A)anywhere in the project
B)only in the procedure where the Dim statement is shown
C)anywhere in the project if the variable name is changed to NAME_String
D)only once in the procedure
Question
Which of the following is the correct code that will display the value in TotalSalesDecimal with a percent sign and 2 decimals?

A)TotalSalesDecimal(2)
B)TotalSalesPercent(2)
C)TotalSalesDecimal.ToString("P2")
D)TotalSalesDecimal.ToString(%2)
Question
A variable that is declared in the Declarations section of a form is a(n)_______.

A)module-level variable
B)local variable
C)block variable
D)general variable
Question
What will be the value of AnswerInteger after execution of the following line of code? Assume that NumberAInteger = 6,NumberBInteger = 4,NumberCInteger = 2
AnswerInteger = (NumberAInteger + NumberBInteger)* (NumberAInteger / NumberCInteger)

A)6
B)30
C)27
D)None of these
Question
Which of the following is NOT a valid method for parsing?

A)Integer.Parse
B)Decimal.Parse
C)Parse.String
D)All of these are valid
Question
MessageBox.Show("Hello","Goodbye")will display _______.

A)"Hello" in the message box titlebar and "Goodbye" in the body of the message box
B)"Goodbye" in the body of the message box;"Hello" in the project's title bar
C)"Goodbye" in the message box titlebar and "Hello" in the body of the message box
D)None of these
Question
You can use the _______method to round decimal values to the desired number of decimal positions.

A)ToDecimal
B)ToSingle
C)ToRound
D)Round
Question
The Visual Basic statement that requires all variables to be declared is _______.

A)Dim
B)Option Strict On
C)Option Explicit On
D)Declarations
Question
What will be the value of TotalInteger after execution of this statement? Assume that ValueInteger = 2.
TotalInteger = ((ValueInteger + 2)* (ValueInteger + 4))/ ValueInteger + 1

A)13
B)8
C)12
D)None of these
Question
What statement should be used to declare a variable that is accessible from all procedures of a form?

A)Dim
B)Const
C)Private
D)Public
Question
What will be the value of AnswerInteger after execution of these statements? Const NumberAInteger as Integer = 6
Const NumberBInteger as Integer = 4
Const NumberCInteger as Integer = 2
AnswerInteger = NumberAInteger + NumberBInteger * NumberCInteger

A)6
B)14
C)20
D)48
Question
Explain how you would decide which data type to use when declaring variables and constants.
Question
In order to control the number of decimals that will appear when a number is displayed,you can use _______.

A)a conversion function
B)a string variable
C)a constant
D)the format specifier codes
Question
Which of the following has the highest order of precedence in arithmetic expressions?

A)Multiplication and division
B)Addition and subtraction
C)Exponentiation
D)Operators are not significant;all calculations are evaluated from left to right.
Question
Integer.Parse is used to _______.

A)convert data in a textbox to a numeric value with no decimal places
B)properly align decimal positions in a numeric value
C)add a dollar sign ($)to improve the way the output looks
D)convert data in a textbox to a numeric value with 2 decimal places
Question
Write code using nested Try/Catch blocks where you will store data from text boxes named QuantityTextBox and PriceTextBox into variables named QuantityInteger and PriceDecimal.Handle any exceptions by displaying a message in a message box if the text boxes do not contain valid data.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/58
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 3: Variables, Constants, and Calculations
1
The Parse method and exception handling can be used to eliminate the problems encountered when the user does not enter a value into a field.
True
2
Variables that are declared in the Declarations section of a form module are available to all procedures in the form.
True
3
Numeric constants may contain only the digits ( 0 - 9 ),a decimal point,and a sign ( + or - )at the left side.
True
4
Assume that a variable is declared in the Declarations section of a form and named TOTAL_PAY_Decimal.This variable,TOTAL_PAY_Decimal,will be visible to all procedures in that form even though the programmer did not follow the naming conventions in the textbook and name the variable TotalPayDecimal.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
5
It is a good idea to set Option Strict On,in the Visual Basic environment in order to detect misspelled variable names when the project is run.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
6
GrandTotalDecimal is a valid variable name.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
7
Data whose value may not be changed during the execution of a project is referred to as a constant.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
8
A constant contains data whose value may be changed during the execution of a project.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
9
A variable named SalesTotalDecimal that is declared in the CalculateButton_Click event procedure can be used in any procedure of the form.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
10
When Option Explicit is turned on,you can use any variable name without first declaring it.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
11
A numeric variable that is declared with the Dim statement in a local procedure is initialized to zero each time the procedure is called.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
12
Constants can store string or numeric values.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
13
A variable that will store totals and that will be available to all procedures in the form must be declared as a constant.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
14
SCHOOL_NAME_String is in the correct format for a constant that holds the name of your school.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
15
If you are declaring a variable that will be used in calculations,you may use the string data type.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
16
When naming a constant,you should use uppercase characters in the name with an underscore between the words and the data type at the end of the name.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
17
Although it is best to always declare the data type on a Dim statement,the data type is optional.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
18
When using the format specifier codes,you can specify the number of digits to appear to the right of the decimal point.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
19
Variables that are declared inside a procedure can be used as counters and accumulators.(Ignore Static variables. )
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
20
Calculations may be performed with variables.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
21
Which of the following is NOT a rule for naming identifiers for constants?

A)Include the data type at the end of the identifier.
B)Everything in the identifier's name should be capitalized except the data type.
C)Identifiers for constants should begin with a prefix of Const.
D)Identifiers for constants should use an underscore between words.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
22
A _______ variable is declared inside a procedure.

A)namespace
B)module-level
C)local
D)block
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
23
Message boxes can be used to notify the user if input data is not a reasonable value.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
24
The data type that is used for decimal fractions is _______.

A)Decimal
B)Short
C)Integer
D)Fraction
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
25
Which of the following is NOT a rule for naming identifiers?

A)Identifiers for constants should use an underscore between words.
B)Identifiers should use periods to separate words.
C)Identifiers should list the data type at the end of the name.
D)Identifiers cannot contain embedded blanks.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
26
When you declare a variable or a named constant,Visual Basic reserves an area of memory and assigns it a name called a(n)_______.

A)identifier
B)identity
C)declaration
D)dimension
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
27
Message boxes can contain buttons.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
28
The reserved Visual Basic word,Dim,is short for dimension,which means _______.

A)declaration
B)size
C)storage location
D)identifier
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
29
Where should the statement: Dim CounterInteger As Integer appear if you plan to use CounterInteger in only one event procedure?

A)The Declarations section of the form
B)The Form_Load procedure
C)The event procedure where CounterInteger will be used
D)The Namespace Constants file
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
30
Intrinsic constants are _______.

A)declared using the keyword Const
B)declared using the keyword Dim
C)placed in the Declarations section of a form
D)built into Visual Studio
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
31
Which of the following is a valid statement that can be used to declare a local variable that will store whole numbers?

A)Dim IndexWhole as Whole
B)Dim IndexString as String
C)Dim IntegerIndex as Index
D)Dim IndexInteger as Integer
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
32
Variables declared within a button's click-event are _____ variables.

A)local
B)module-level
C)namespace
D)private
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
33
Which of the following does not follow the conventions for naming identifiers?

A)UnitsEnrolledDecimal
B)ZipCodeString
C)Amount.Due.Decimal
D)COUNTRY_OF_BIRTH_String
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
34
If Option Strict is turned off and a declaration statement does not specify a data type,it will default to _______.

A)boolean
B)string
C)object
D)variable
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
35
Which of the following is NOT a valid rule for naming identifiers?

A)Names may contain underscores.
B)Names may contain letters.
C)Names may contain digits.
D)Names may contain spaces.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
36
Which of the following is NOT a valid Visual Basic data type?

A)Integer
B)Real
C)Decimal
D)String
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
37
Where should the statement: Const ACCOUNT_NUMBER_String As String = "A45" appear if you plan to use ACCOUNT_NUMBER_String in more than one procedure?

A)The Declarations section of the form
B)The Form_Load procedure
C)The event procedure where ACCOUNT_NUMBER_String will be used
D)The Namespace Constants file
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
38
The length of identifiers is limited to _______.

A)1 to 8 characters
B)1 to 256 characters
C)1 to 4,000 characters
D)1 to 16,383 characters
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
39
Declaration statements _______.

A)can only be written inside a procedure
B)are only allowed in the Declarations section of a form
C)give variables and constants names,and specify the type of data they will hold
D)are not needed for constants
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
40
Which of the following is a valid statement that can be used to declare a local variable that will store fractions?

A)Dim IndexFraction As Fraction
B)Dim IndexString As String
C)Dim IndexDecimal As Decimal
D)Dim IndexInteger As Integer
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
41
To trap or catch exceptions,use a _______ block and enclose any statement(s)that might cause an error.

A)With \ End With
B)Try \ Catch
C)For \ Next
D)TheException
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
42
Using the order of precedence and the formula below,what is AnswerInteger if?: NumberOneInteger = 2,NumberTwoInteger = 12,NumberThreeInteger = 20,and NumberFourInteger = 6
AnswerInteger = NumberOneInteger * (NumberTwoInteger + NumberThreeInteger)- NumberFourInteger / NumberOneInteger

A)19
B)41
C)61
D)None of these
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
43
If a procedure contains a Dim statement and NameString is assigned as the identifier,NameString can be used _______.

A)anywhere in the project
B)only in the procedure where the Dim statement is shown
C)anywhere in the project if the variable name is changed to NAME_String
D)only once in the procedure
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
44
Which of the following is the correct code that will display the value in TotalSalesDecimal with a percent sign and 2 decimals?

A)TotalSalesDecimal(2)
B)TotalSalesPercent(2)
C)TotalSalesDecimal.ToString("P2")
D)TotalSalesDecimal.ToString(%2)
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
45
A variable that is declared in the Declarations section of a form is a(n)_______.

A)module-level variable
B)local variable
C)block variable
D)general variable
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
46
What will be the value of AnswerInteger after execution of the following line of code? Assume that NumberAInteger = 6,NumberBInteger = 4,NumberCInteger = 2
AnswerInteger = (NumberAInteger + NumberBInteger)* (NumberAInteger / NumberCInteger)

A)6
B)30
C)27
D)None of these
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
47
Which of the following is NOT a valid method for parsing?

A)Integer.Parse
B)Decimal.Parse
C)Parse.String
D)All of these are valid
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
48
MessageBox.Show("Hello","Goodbye")will display _______.

A)"Hello" in the message box titlebar and "Goodbye" in the body of the message box
B)"Goodbye" in the body of the message box;"Hello" in the project's title bar
C)"Goodbye" in the message box titlebar and "Hello" in the body of the message box
D)None of these
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
49
You can use the _______method to round decimal values to the desired number of decimal positions.

A)ToDecimal
B)ToSingle
C)ToRound
D)Round
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
50
The Visual Basic statement that requires all variables to be declared is _______.

A)Dim
B)Option Strict On
C)Option Explicit On
D)Declarations
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
51
What will be the value of TotalInteger after execution of this statement? Assume that ValueInteger = 2.
TotalInteger = ((ValueInteger + 2)* (ValueInteger + 4))/ ValueInteger + 1

A)13
B)8
C)12
D)None of these
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
52
What statement should be used to declare a variable that is accessible from all procedures of a form?

A)Dim
B)Const
C)Private
D)Public
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
53
What will be the value of AnswerInteger after execution of these statements? Const NumberAInteger as Integer = 6
Const NumberBInteger as Integer = 4
Const NumberCInteger as Integer = 2
AnswerInteger = NumberAInteger + NumberBInteger * NumberCInteger

A)6
B)14
C)20
D)48
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
54
Explain how you would decide which data type to use when declaring variables and constants.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
55
In order to control the number of decimals that will appear when a number is displayed,you can use _______.

A)a conversion function
B)a string variable
C)a constant
D)the format specifier codes
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
56
Which of the following has the highest order of precedence in arithmetic expressions?

A)Multiplication and division
B)Addition and subtraction
C)Exponentiation
D)Operators are not significant;all calculations are evaluated from left to right.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
57
Integer.Parse is used to _______.

A)convert data in a textbox to a numeric value with no decimal places
B)properly align decimal positions in a numeric value
C)add a dollar sign ($)to improve the way the output looks
D)convert data in a textbox to a numeric value with 2 decimal places
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
58
Write code using nested Try/Catch blocks where you will store data from text boxes named QuantityTextBox and PriceTextBox into variables named QuantityInteger and PriceDecimal.Handle any exceptions by displaying a message in a message box if the text boxes do not contain valid data.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 58 flashcards in this deck.