Introduction To Programming Using Visual Basic 2012 9th Edition Schneider Test Bank 1
Introduction To Programming Using Visual Basic 2012 9th Edition Schneider Test Bank 1
Chapter 4 Decisions
3. Which of the following expressions has as its value the words "Hello World” surrounded by
quotation marks?
(A) "Hello World"
(B) Chr(34) & "Hello World"
(C) Chr(34) & Hello World & Chr(34)
(D) Chr(34) & "Hello World" & Chr(34)
D
4. The statement txtBox.Text = Chr(162) causes Visual Basic to display the cents symbol
(ANSI 162) in the text box, regardless of the font in use. (T/F)
F
11. When using the logical operator “And”, what part of the expression must be true?
(A) only the left part
(B) only the right par
(C) both parts
(D) either the left or right part, but not both
C
12. When using the logical operator “Or”, what part of the expression must be true?
(A) only the left part
(B) only the right part
(C) either the left or right part, but not both
(D) either the left or right part
D
15. Which value for x would make the following condition true: Not (x >= 5)
(A) x is equal to 7
(B) x is equal to 4
(C) x is equal to 5.001
(D) All of the above
B
16. Which value for x would make the following condition true: (x >= 5) And (x <= 6)
(A) x is equal to 7
(B) x is equal to 5
(C) x is equal to 5.001
(D) B and C
D
19. In Visual Basic, the letter j is considered to be greater than the letter y. (T/F)
F
20. The And operator requires that both conditions be true for the compound condition to be
true. (T/F)
T
21. If two simple conditions are true, the compound condition created from them by the Or
operator is also true. (T/F)
T
23. If two simple conditions are true, the compound condition created from them by the And
operator is also true. (T/F)
T
26. Assume that A, B, and C are conditions, with A being true, B being true, and C being false.
Give the truth value of (A And Not (B or C)).
False
27. Assume that A, B, and C are conditions, with A being true, B being true, and C being false.
Give the truth value of (Not (A And B)).
False
31. Two strings are compared working from left to right, character by character, to determine
which one should precede the other. (T/F)
T
End If
End If
Which one of the following statements is true?
(A) (a) and (b) will produce different outputs.
(B) (b) is not a valid set of Visual Basic instructions.
(C) The two sets of code are equivalent, but (a) is preferred to (b) because (a) is clearer.
(D) The condition statement in (a) is not valid.
C
2. What will be displayed by the following program when the button is clicked?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim a, b, c, x As Double
a = 5
b = 3
c = 6
If a > c Then
x = 1
Else
If b > c Then
x = 2
Else
x = 3
txtBox.Text = CStr(x)
End If
End If
End Sub
(A) 1
(B) 2
(C) 3
(D) None of the above
C
3. What will be the output of the following program when the button is clicked?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim x, y, z As Double
x = 3
y = 3
If x > y Then
z = x + y
Else
z = y - x
End If
txtBox.Text = CStr(z)
End Sub
(A) 6
(B) 3
(C) 0
(D) No output
C
4. What will be the output of the following program when the button is clicked?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim word1, word2, newWord As String
word1 = "shower"
word2 = "about"
newWord = word1.Substring(0, 4) & word2.Substring(0, 3)
If newWord.IndexOf("how") = -1 Then
txtBox.Text = "The new word was not found."
Else
txtBox.Text = "Found it."
End If
End Sub
(A) The new word was not found.
(B) Found it.
(C) Syntax error
(D) No output
B
11. When an If block has completed execution, the program instruction immediately following
the If block is executed. (T/F)
T
14. The Else part of an If block may be omitted if no action is associated with it. (T/F)
T
15. Given that x = 7, y = 2, and z = 4, the following If block will display "TRUE". (T/F)
If (x > y) Or (y > z) Then
txtBox.Text = "TRUE"
End If
T
16. Given that x = 7, y = 2, and z = 4, the following If block will display "TRUE". (T/F)
If (x > y) And (y > z) Then
txtBox.Text = "TRUE"
End If
F
18. No more than one ElseIf statement may occur in any one If block. (T/F)
F
19. No more than one Else statement may occur in any one If block. (T/F)
T
20. A variable declared inside an If block ceases to exist after the block is exited. (T/F)
T
2. Suppose that the selector in a Select Case block is the string variable myVar. Which of the
following is NOT a valid Case clause?
(A) Case "Adams"
(B) Case "739"
(C) Case myVar.Substring(0, 1)
(D) Case myVar.Length
D
3. What will be the output of the following program when the button is clicked?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim name As String = "Washington"
Select Case name
Case "George"
txtBox.Text = "George"
Case "Wash"
txtBox.Text = "Wash"
Case "WASHINGTON"
txtBox.Text = "WASHINGTON"
Case Else
txtBox.Text = "Washington"
End Select
End Sub
(A) WashWashington
(B) Washington
(C) WASHINGTONWashington
(D) No output
B
4. What is the problem (if any) with the following Select Case block which is intended to
determine the price of a movie depending on the patron's age?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim age as Integer, price As Double
age = CInt(InputBox("Enter your age:"))
Select Case age
Case Is >= 65 'Senior citizen
price = 4.50
Case Is >= 5 'Regular price
price = 6.00
Case Is >= 0 'Child (no charge with parents)
price = 0
Case Else
txtBox.Text = "Entry error"
End Select
End Sub
(A) Everyone will get in free at the child rate.
(B) The output will always be "Entry error."
(C) The Case Is statements have bad syntax.
(D) There is nothing wrong.
D
5. What will be the output of the following program when the button is clicked?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim a, b, c, acronym As String
a = "federal"
b = "aviation"
c = "administration"
acronym = a.Substring(0, 1) & b.Substring(0, 1) & c.Substring(0, 1)
Select Case acronym
Case "FAA"
txtBox.Text = "Federal Aviation Administration"
Case "DEA"
txtBox.Text = "Drug Enforcement Agency"
Case Else
txtBox.Text = "Unknown acronym. Sorry."
End Select
End Sub
(A) Federal Aviation Administration
(B) Drug Enforcement Agency
(C) Syntax error
(D) Unknown acronym. Sorry.
D
6. In a Select Case block, if more than one Case clause matches the selector,
(A) only the statements associated with the first matching Case clause will be executed.
(B) all of the statements associated with each matching Case clause will be executed.
(C) only the statements associated with the last matching Case clause will be executed.
(D) the program will malfunction and stop.
A
7. What will be displayed in the list box when the following code runs?
Select Case num
Case 6, 7, 11
lstBox.Items.Add("W")
Case Is < 7
lstBox.Items.Add("X")
Case Is > 5
lstBox.Items.Add("Y")
Case Else
lstBox.Items.Add("Z")
End Select
(A) Z can never be displayed.
(B) W, X and Y will be displayed if the value of num is 6.
(C) W and Y will be displayed if the value of num is 7.
(D) Z will always be displayed.
A
8. Different items appearing in the same value list of a Select Case block must be separated by
a .
(A) semi colon
(B) comma
(C) colon
(D) pair of quotation marks
B
9. Which Case clause will be true whenever the value of the selector in a Select Case block is
between 1 and 5 or is 8?
(A) Case 1 To 8
(B) Case 1 To 5, 8
(C) Case 1 To 8, 5
(D) Case 1 To 5; 8
B
10. Which Case clause will be true whenever the value of the selector in a Select Case block is
greater than or equal to 7?
(A) Case Is >7
(B) Case Is = 8
(C) Case Is >= 7
(D) Case Is <= 8
C
11. What type of items are valid for use in the value list of a Case clause?
(A) literals
(B) variables
(C) expressions
(D) All of the above
D
12. The Case Else part of a Select Case block is optional. (T/F)
T
13. One may use an If block within a Select Case block. (T/F)
T
14. One may use a Select Case block within an If block. (T/F)
T
16. One may use a Select Case block within another Select Case block. (T/F)
T
17. Select Case choices are determined by the value of an expression called a selector. (T/F)
T
18. Items in the value list must evaluate to a literal of the same type as the selector. (T/F)
T
20. You can specify a range of values in a Case clause by using the To keyword. (T/F)
T
21. A variable declared inside a Select Case block cannot be referred to by code outside of the
block. (T/F)
T
1. At design time, values can be placed into a list box via the .
(A) String Editor
(B) String Collection Editor
(C) Collection Editor
(D) Items Editor
B
9. . The value of lstBox.Text is the currently selected item of the list box. (T/F)
T
10. Which of the following techniques does NOT always toggle the checked and unchecked
state of a check box control?
(A) Click on the square or its caption with the mouse.
(B) Press the spacebar when the square has the focus.
(C) Press Alt+Access key (if an access key has been specified).
(D) Set the Checked property equal to 1.
D
11. Which of the following techniques always toggles the "on" and "off" states of a radio button
control?
(A) Click on the circle or its caption with the mouse.
(B) Press the spacebar when the circle has the focus.
(C) Press on another radio button in the same group box.
(D) Set the Checked property equal to True.
(E) None of the above
E
12. What is the key difference between a group of check boxes attached to a group box and a
group of radio buttons attached to a group box?
(A) Only radio buttons can be toggled.
(B) Only one radio button at a time can be checked.
(C) Check boxes cannot be attached to a group box.
(D) The only difference is the shape of the control.
B
13. When a check box is checked, the value of the Checked property will be
(A) True.
(B) False.
(C) 1.
(D) 0.
A
14. The title (as seen by the user) for the group box control is set by which one of the following
properties?
(A) Text
(B) Name
(C) Tag
(D) Anchor
A
15. When the user clicks on a check box control at run time, which one of the following events is
raised (in addition to the Click event)?
(A) ControlAdded
(B) Invalidated
(C) StyleChanged
(D) CheckedChanged
D
16. A check box control named chkFirst contains the following code in its CheckedChanged
event procedure. Which of the following is true concerning the use of this control?
Dim message As String = "hello"
MessageBox.Show(message)
(A) The message "hello" will appear when the user checks the control but not when it is
unchecked.
(B) The message "hello" will appear when the user unchecks the control but not when it is
checked.
(C) The message "hello" will appear when the user checks the control and again when it is
unchecked.
(D) The message "hello" will not appear using this code.
C
17. Suppose there are four radio button controls attached to a group box control on a form. How
many radio buttons can be selected (that is, be “on”) at any given time?
(A) 2
(B) 1
(C) 3
(D) 4
B
18. A radio button named radButton is placed on a form, and the statement
MessageBox.Show(radButton.Checked) is placed in its CheckedChanged event procedure.
At run time, what result will be displayed in the message box when the user clicks on
radButton?
(A) 1
(B) True
(C) 2
(D) False
B
19. After several controls of the same type have been created, they can be moved inside a group
box and thereby become attached to it. (T/F)
T
20. With a check box control, toggling the state of the small square raises the CheckChanged
event. (T/F)
T
21. Group boxes are passive objects used to group related sets of controls. (T/F)
T
22. Programmers frequently write event procedures for the group box control. (T/F)
F
23. If you set a group box control’s Visible property to False, the attached controls will still
remain visible. (T/F)
F
24. When a check box control has the focus, the spacebar can be used to invoke its
CheckedChanged event. (T/F)
T
25. As with the button and check box controls, an access key can be set up by placing an
ampersand in front of a letter in the radio button’s Text property setting. (T/F)
T
26. Suppose a form contains two group box controls with one radio button placed on each. In
this case, both radio buttons can be selected (or turned “on”) at the same time. (T/F)
T