1 tom.com
chapter 7
Variables and Expressions
True-False Questions
1. Every variable has a name, data value, and data type.
Answer: True Level: Easy
Section: 7-1 Page: 142
2. There are two types of integer data types: numeric and floating point.
Answer: False Level: Easy
Section: 7-1 Page: 143
3. It is better to use integer data types because they are processed faster.
Answer: True Level: Easy
Section: 7-1 Page: 143
4. The string data type holds characters found in the Unicode character set, which is a subset of the larger ASCII character set.
Answer: False Level: Moderate
Section: 7-1 Page: 144
5. String and Char data types are actually stored as numeric values in the computer.
Answer: True Level: Easy
Section: 7-1 Page: 144
6. Boolean data types have three possible values: true, false, or null.
Answer: False Level: Easy
Section: 7-1 Page: 144
7. The advantage of the object data type is that it uses a 4-byte pointer in addition to the data itself.
Answer: False Level: Moderate
Section: 7-1 Page: 145
8. The Date data type holds the day, month, and year while the Time data type hold seconds, minutes, and hours.
Answer: False Level: Moderate
Section: 7-1 Page: 145
9. is flexible enough that you do not have to declare a variable before using it.
Answer: False Level: Easy
Section: 7-2 Page: 146
10. You can declare more than one variable with a single Dim statement.
Answer: True Level: Easy
Section: 7-2 Page: 146
11. Multiple variables declared in the same Dim statement can be of different data types.
Answer: False Level: Moderate
Section: 7-2 Page: 146
12. A statement separate from the Dim statement is needed to initialize a variable.
Answer: False Level: Easy
Section: 7-2 Page: 146
13. A Constant must be initialized when it is declared.
Answer: True Level: Easy
Section: 7-2 Page: 148
14. Constants, but not variables, must start with a letter.
Answer: False Level: Moderate
Section: 7-2 Page: 147
15. Constants are used to make the program easier to read and maintain.
Answer: True Level: Easy
Section: 7-2 Page: 148
16. Variables, constants, and operators are combined to form expressions.
Answer: True Level: Easy
Section: 7-3 Page: 149
17. Using arithmetic operators will always result in a logical output.
Answer: False Level: Easy
Section: 7-3 Page: 149
18. Using comparison operators will always result in a logical output.
Answer: True Level: Easy
Section: 7-3 Page: 150
19. If X = 3 and Y = 2, then X ^ 2 * Y = 18.
Answer: True Level: Moderate
Section: 7-3 Page: 151
20. If X = 2 and Y = 6, then 4 + Y / X = 5.
Answer: False Level: Moderate
Section: 7-3 Page: 151
21. The left side of an assignment statement always has an expression.
Answer: False Level: Easy
Section: 7-4 Page: 152
22. Assignment statements are used to store data in a variable or property.
Answer: True Level: Easy
Section: 7-4 Page: 152
23. The equal sign (=) is used both as a comparison operator and an assignment operator.
Answer: True Level: Easy
Section: 7-4 Page: 152
24. If an equal sign can be replaced by a greater than sign, it is being used as an assignment operator.
Answer: False Level: Moderate
Section: 7-4 Page: 152
25. The CDbl intrinsic function will take a double data type and convert it into another data type.
Answer: False Level: Moderate
Section: 7-5 Page: 153
26. The IsNumeric intrinsic function will return a value of true if the string can be changed into a numeric value.
Answer: True Level: Easy
Section: 7-5 Page: 153
27. The Val intrinsic function will return a numeric value for the string “one”.
Answer: True Level: Hard
Section: 7-5 Page: 154
28. One limitation of the intrinsic functions is that there are no financial functions.
Answer: False Level: Easy
Section: 7-5 Page: 154
29. All intrinsic functions take zero or one arguments.
Answer: False Level: Easy
Section: 7-5 Page: 154
30. The FormatCurrency function takes a number and returns a string formatted in dollars and cents.
Answer: True Level: Easy
Section: 7-5 Page: 153
31. A dialog box is like a pop-up window that gets input from and provides output to the end user.
Answer: True Level: Easy
Section: 7-6 Page: 156
32. The text typed into the InputBox must be assigned to a string variable.
Answer: False Level: Moderate
Section: 7-6 Page: 156
33. The prompt argument of the InputBox is optional.
Answer: False Level: Easy
Section: 7-6 Page: 156
34. The MsgBox function will display a dialog box if the vbDisplay argument is used.
Answer: False Level: Easy
Section: 7-6 Page: 156
35. No more than two string expressions can be combined in the MsgBox prompt argument.
Answer: False Level: Moderate
Section: 7-6 Page: 157
36. The VB constant vbCrLf is used to create a MsgBox message with multiple lines.
Answer: True Level: Easy
Section: 7-6 Page: 157
37. The TextBox can both get input from the user and give output to the user.
Answer: True Level: Easy
Section: 7-7 Page: 158
38. When the DataType property of the TextBox is set to Number, whatever the user types into the TextBox is stored in the Text property as a numeric data type.
Answer: False Level: Moderate
Section: 7-7 Page: 158
39. Only the Copy method places selected TextBox text in the clipboard.
Answer: False Level: Easy
Section: 7-7 Page: 159
40. The TextBox property MaxLength can be used to make sure the user does not enter more than nine characters for a Social Security Number.
Answer: True Level: Easy
Section: 7-7 Page: 158
41. Scroll bars will automatically appear if too much data is typed into a Textbox.
Answer: False Level: Moderate
Section: 7-7 Page: 158
42. Scroll bars will automatically appear if too many items are entered into a Listbox.
Answer: True Level: Moderate
Section: 7-8 Page: 161
43. The Alphabetical Property of a ListBox will sort the items in alphabetical order.
Answer: False Level: Easy
Section: 7-8 Page: 160
44. The Index for the Items in a ListBox is zero-based.
Answer: True Level: Moderate
Section: 7-8 Page: 160
45. The Items.Clear method of a ListBox will clear the selected item.
Answer: False Level: Easy
Section: 7-8 Page: 160
46. Items are added to the ListBox during run time with the Properties Window.
Answer: False Level: Moderate
Section: 7-8 Page: 161
47. The ComboBox has a Text Property and an Items Property.
Answer: True Level: Easy
Section: 7-9 Page: 162
48. The Items property of the ComboBox contains a collection of individual Items.
Answer: True Level: Moderate
Section: 7-9 Page: 162
49. The ComboBox combines features of the ListBox and InputBox.
Answer: False Level: Easy
Section: 7-9 Page: 162
50. In a ComboBox the user can always type in a new value to the list of items.
Answer: False Level: Easy
Section: 7-9 Page: 162
Multiple Choice Questions
51. Which is not an integer data type?
a.) Single
b.) Byte
c.) Short
d.) Integer
e.) Long
Answer: a Level: Moderate
Section: 7-1 Page: 143
52. Which is a numeric data type?
a.) Floating point
b.) Integer
c.) Boolean
d.) Both a and b.
e.) All of the above.
Answer: d Level: Moderate
Section: 7-1 Page: 143
53. Which sequence of char data types is listed from lowest to highest?
a.) a, A, z, Z
b.) a, z, A, Z
c.) A, a, Z, z
d.) A, Z, a, z
e.) z, a, Z, A
Answer: d Level: Moderate
Section: 7-1 Page: 145
54. The Date data type does not hold which type of information.
a.) Seconds
b.) Hours
c.) Days
d.) Months
e.) Quarters
Answer: e Level: Easy
Section: 7-1 Page: 145
55. The Boolean data type:
a.) is unsigned.
b.) has two states.
c.) is displayed by the program as yes or no.
d.) Both a and b.
e.) All of the above.
Answer: d Level: Moderate
Section: 7-1 Page: 144
56. Which is a valid statement for declaring a variable?
a.) Const Form As Integer
b.) Const myForm As Integer
c.) Dim Form As Integer
d.) Dim myForm As Integer
e.) All of the above.
Answer: d Level: Moderate
Section: 7-2 Page: 147
57. identifiers:
a.) are case sensitive.
b.) can begin with an underscore.
c.) can begin with a number.
d.) Both a and b.
e.) All of the above.
Answer: b Level: Moderate
Section: 7-2 Page: 147
58. The name of a constant:
a.) must both begin with a letter and be all upper case.
b.) does not have to begin with a letter but must be all upper case.
c.) must begin with a letter but can be upper or lower case.
d.) does not have to begin with a letter and be either upper or lower case.
e.) None of the above.
Answer: d Level: Moderate
Section: 7-2 Page: 148
59. The proper operator precedence, from first to last, is:
a.) logical, comparison, and arithmetic.
b.) arithmetic, comparison, and logical.
c.) arithmetic, logical, and comparison.
d.) comparison, arithmetic, and logical.
e.) logical, arithmetic, comparison.
Answer: b Level: Moderate
Section: 7-3 Page: 151
60. With A = False and B = True, which statement evaluates as True?
a.) A AND A
b.) A AND B
c.) B AND A
d.) B AND B
e.) None are true.
Answer: d Level: Easy
Section: 7-3 Page: 151
61. With A = False and B = True, which statement evaluates as False?
a.) A OR A
b.) A OR B
c.) B OR A
d.) B OR B
e.) None are true.
Answer: a Level: Easy
Section: 7-3 Page: 151
62. Which operator is evaluated first?
a.) NOT
b.) AND
c.) XOR
d.) OR
e.) They are always evaluated left-to-right.
Answer: a Level: Moderate
Section: 7-3 Page: 151
63. The left side of an assignment statement will hold:
a.) a variable.
b.) an object property.
c.) an expression.
d.) Both a and b.
e.) All of the above.
Answer: d Level: Easy
Section: 7-4 Page: 152
64. The right side of an assignment statement will hold:
a.) a variable.
b.) an object property.
c.) an expression.
d.) Both a and b.
e.) All of the above.
Answer: c Level: Easy
Section: 7-4 Page: 152
65. Which function will return the monthly payments of a loan?
a.) Pay (Rate, PV, Nper)
b.) Pmt (Rate, Nper, PV)
c.) FV (Rate, Nper, Pmt)
d.) FV (Rate, Nper, PV)
e.) None of the above.
Answer: b Level: Easy
Section: 7-5 Page: 154
66. Which function returns the numbers represented in the string “$56.7”?
a.) Abs
b.) CDbl
c.) Int
d.) Rnd
e.) Val
Answer: b Level: Moderate
Section: 7-5 Page: 153
67. What will the function Val ($165.30) return?
a.) 0
b.) 165
c.) 165.30
d.) $165.30
e.) An error
Answer: a Level: Easy
Section: 7-5 Page: 153
68. Which function displays a pop-up window?
a.) MsgBox
b.) InputBox
c.) TextBox
d.) Both a and b.
e.) All of the above.
Answer: d Level: Easy
Section: 7-6 Page: 156
69. Which is true about the prompt argument?
a.) It can be made of multiple values concatenated into one string.
b.) It can include the vbCrLf constant.
c.) It can include the ampersand symbol to concatenate strings.
d.) Both a and b.
e.) All of the above.
Answer: e Level: Easy
Section: 7-6 Page: 157
70. In order to process a number typed in a TextBox the programmer must:
a.) use the Val function to convert the Text value.
b.) use the CDbl function to convert the Text value.
c.) use the IsNumeric function to convert the Text value.
d.) Both a and b.
e.) All of the above.
Answer: d Level: Moderate
Section: 7-7 Page: 158
71. Which TextBox method does not use the clipboard?
a.) Clear
b.) Copy
c.) Cut
d.) Paste
e.) All of these methods use the clipboard.
Answer: a Level: Easy
Section: 7-7 Page: 159
72. Which TextBox property should always be changed first?
a.) AcceptsReturn
b.) BorderStyle
c.) Font
d.) Name
e.) Text
Answer: d Level: Moderate
Section: 7-7 Page: 158
73. Which is not a valid value for the ListBox SectionMode Property?
a.) None
b.) One
c.) MultiSimple
d.) MultiExtended
e.) All of the above.
Answer: e Level: Moderate
Section: 7-8 Page: 160
74. Setting the SelectedIndex property of a ListBox to -1 will:
a.) cause an error.
b.) cannot be done.
c.) de-select any selected item.
d.) Both a and b.
e.) All of the above.
Answer: c Level: Hard
Section: 7-8 Page: 160
75. Which method of a ListBox will remove just one item at a time?
a.) Items.RemoveAt
b.) Item.RemoveAt
c.) Items.ClearAt
d.) Item.ClearAt
e.) Items.Clear
Answer: a Level: Moderate
Section: 7-8 Page: 160
76. The Items property of a ComboBox:
a.) is a collection of items.
b.) is the same as the Items property of a ListBox.
c.) contains methods and properties.
d.) Both a and b.
e.) All of the above.
Answer: e Level: Moderate
Section: 7-9 Page: 162
77. Which value for the ComboBox DropDownStyle property allows a user to type in data?
a.) DropDown
b.) DropDownSimple
c.) DropDownList
d.) Both a and b.
e.) All of the above.
Answer: a Level: Moderate
Section: 7-9 Page: 164
78. Which two controls combined to form the ComboBox control?
a.) ListBox and TextBox
b.) ListBox and InputBox
c.) ListBox and MsgBox
d.) Label and TextBox
e.) Label and InputBox
Answer: a Level: Easy
Section: 7-9 Page: 162
Fill in the Blank Questions
79. The best integer data type to use with a 32-bit processor is the ___Integer___ type.
Level: Moderate
Section: 7-1 Page: 143
80. Any numeric value that has a decimal must be stored as a(n) ___floating-point___ data type.
Level: Easy
Section: 7-1 Page: 143
81. The ___Char___ data type is a single character while the ___String___ data type is a sequence of characters.
Level: Easy
Section: 7-1 Page: 144
82. When no data type is included in the Dim statement of a variable, uses the ___Object___ data type as the default.
Level: Moderate
Section: 7-1 Page: 145
83. A variable is declared with the ___Dim___ statement.
Level: Easy
Section: 7-2 Page: 146
84. The unique name of a variable is known as a(n) ___identifier___.
Level: Easy
Section: 7-2 Page: 147
85. The compiler sees the variable names BookCost and bookcost as the same. This is an example of how identifiers are ___case insensitive___.
Level: Moderate
Section: 7-2 Page: 147
86. ___Constants___ are easier to identify when they are typed in all upper case.
Level: Easy
Section: 7-2 Page: 148
87. Addition, subtraction, multiplication, and exponents are examples of ___arithmetic___ operators.
Level: Easy
Section: 7-3 Page: 149
88. Greater Than, Less Than, Not Equal, and Equal are examples of ___comparison___ operators.
Level: Easy
Section: 7-3 Page: 150
89. NOT, OR, AND, and XOR are examples of ___logical___ operators.
Level: Easy
Section: 7-3 Page: 151
90. When multiple operators are present in a complex expression, using ___parenthesis___ will make the expression easier to read.
Level: Moderate
Section: 7-3 Page: 151
91. We use ___assignment___ statements to store data in variables or properties.
Level: Easy
Section: 7-4 Page: 152
92. A(n) ___expression___ is found on the right side of an assignment statement.
Level: Easy
Section: 7-4 Page: 152
93. To make sure a string can be converted into a number use the ___IsNumeric___ function.
Level: Easy
Section: 7-5 Page: 153
94. The function that will return the future value of an annuity is the ___FV___ function.
Level: Easy
Section: 7-5 Page: 155
95. The ___Rnd___ function will return a random number between 0 and 1.
Level: Easy
Section: 7-5 Page: 153
96. When the user presses the ___Cancel___ button in the InputBox an empty string is returned.
Level: Moderate
Section: 7-6 Page: 156
97. The ___title___ argument in the InputBox function is optional.
Level: Moderate
Section: 7-6 Page: 156
98. The ___InputBox___ function displays a text box in its dialog box, the ___MsgBox___ function does not.
Level: Easy
Section: 7-6 Page: 157
99. The VB constant ___vbCrLf___ causes a carriage return and line feed to be inserted into the prompt argument.
Level: Moderate
Section: 7-6 Page: 157
100. The ___AppendText___ TextBox Method will add text to the end of the existing text.
Level: Easy
Section: 7-7 Page: 159
101. The VB constant, vbCrLf, will act like pressing the enter key when using a ___multiline__ TextBox.
Level: Hard
Section: 7-7 Page: 158
102. The ___Text___ property of a TextBox holds the data in the TextBox.
Level: Easy
Section: 7-7 Page: 158
103. The ___Undo___ method of a TextBox will reverse the last edit operation in the TextBox.
Level: Moderate
Section: 7-7 Page: 159
104. The ___lst___ prefix is used to identify the name of a ListBox.
Level: Easy
Section: 7-8 Page: 160
105. The ___SelectedIndex___ property of a ListBox will return a -1 when no item is selected.
Level: Moderate
Section: 7-8 Page: 160
106. The ___Items.Add___ method of the ListBox will append text to the end of the list.
Level: Moderate
Section: 7-8 Page: 160
107. The ___Items___ property of the ListBox is an object with a set of properties and methods.
Level: Moderate
Section: 7-8 Page: 160
108. The ___cbo___ prefix is used to identify the name of a ComboBox.
Level: Easy
Section: 7-9 Page: 162
109. If the DropDownStyle property of a ComboBox is set to ___DropDownList___ the user cannot type text into the ComboBox.
Level: Moderate
Section: 7-9 Page: 162
110. The ComboBox combines properties of the ___ListBox___ and ___TextBox___.
Level: Moderate
Section: 7-9 Page: 162
Essay Questions
111. Write code to load a ListBox with the cities “Detroit”, “Denver”, and “Dublin”. Make sure the cities are listed in alphabetical order and that the second item in the list is selected.
lstCity.Items.Add("Detroit")
lstCity.Items.Add("Denver ")
lstCity.Items.Add("Dublin")
lstCity.Sorted = True
lstCity.SelectedIndex = 2
112. What are the required rules for naming variables and constants? What are the suggested rules?
Both variables and constants are considered Identifiers and as such must (1) begin with either a letter character or the underscore character, (2) only contain letters, numbers, or the underscore, and (3) not be the same as any reserved words (i.e. Dim, Integer, String, etc.).
For both variables and constants it is suggested that they start with a letter and that they should be easy to understand. To be easily understandable the names should be composed of complete words that clearly describe the variable. However the names should not be so long that they are difficult to manage.
To distinguish variables and constants, it is suggested that constants be all CAPITAL LETTERS while variables are in a mixed case where the First Letter of each word is capitalized.
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.