Chapter 03
Chapter 03
Chapter 03
1. What is the correct statement when declaring and assigning the value of 100 to an Integer
variable called numPeople?
(A) Dim numPeople = 100
(B) Dim numPeople = Int(100)
(C) numPeople = 100
(D) Dim numPeople As Integer = 100
D
3. The type of error that is normally spotted by the Code Editor is:
(A) runtime
(B) logic
(C) syntax
(D) user
C
4. Which of the following arithmetic operations has the highest level of precedence?
(A) +-
(B) */
(C) ^
(D) ()
D
7. Suppose the Double variable num has the value 123.4567. What value will the following
statement assign to num?
num = Math.Round(num, 2)
(A) 123.4567
(B) 123.457
(C) 123.45
(D) 123.46
D
8. What value will be assigned to the numeric variable x when the following statement is
executed?
x = 2 + 3 * 4
(A) 20
(B) 14
(C) 92
(D) 234
B
9. Which of the following statements declare the variables a and b as type Integer?
(A) a = 0: b = 0
(B) Dim a, b
(C) Dim a & b As Integer
(D) Dim a, b As Integer
D
10. Assume that x, y, and temp are Integer variables. Which of the following lines of code swaps
the values of x and y?
(A) x = y
y = x
(B) x = temp
x = y
y = temp
(C) temp = x
x = y
y = temp
(D) x = y
temp = x
y = temp
C
12. Given x = 3 and y = 1, what value will be assigned to the Double variable w when the
following statement is executed?
w = (x + y) / (x y)
(A) 1
(B) 2
(C) 3
(D) None of the above
B
13. What will be displayed when the following lines are executed?
Dim x As Double = 3, y As Double = 1
Dim z As Double
z = x + (y * x)
x = y
z = x + z
lstBox.Items.Add(x + y + z)
(A) 4
(B) 9
(C) 10
(D) None of the above
B
14. Which of the following is the same as 2 ^ 3?
(A) 2*2*2
(B) 2*3
(C) 2+2+2
(D) 3*3
A
17. When declaring a variable that will refer to a submarine, a good name for the variable is sub.
(T/F)
F
18. The function Math.Int will always round mixed numbers down to the next lowest integer.
(T/F)
T
19. When using the equal sign to assign values, the variable on the left hand side of the equal
sign will always receive the value. (T/F)
T
23. A numeric variable that has not been assigned a value has the default value zero. (T/F)
T
24. The following statement is valid. (T/F)
Dim x As Double = 3,542.36
F
25. The statement a + b = c assigns to c the sum of the values of a and b. (T/F)
F
26. The exponential notation used in Visual Basic is exactly the same as standard mathematical
notation. (T/F)
F
27. The lstBox.Items.Clear() statement is used to empty the contents of a list box. (T/F)
T
30. You can use a variable name in almost any place you could use a literal value. (T/F)
T
31. Numeric variables can be initialized to zero or any other number, but once they are
initialized, they cannot be changed. (T/F)
F
35. The following two statements are equivalent, where numVar is a numeric variable. (T/F)
numVar = numVar + 1
numVar += 1
T
36. What is the value of numVar after the following three statements are executed?
Dim numVar As Integer = 5
numVar = numVar + 2
numVar += 3
10
Section 3.2 Strings
2. What is the correct syntax for displaying the value of the String variable myString in a text
box?
(A) txtBox.Text = "myString"
(B) txtBox.Text = myString
(C) txtBox.Text.myString
(D) txtBox.Text = Str(myString)
B
4. Which of the following statements will NOT display the number 5 in the text box?
(A) txtBox.Text = 5
(B) txtBox.Text = "5"
(C) txtBox.Text = CStr("5")
(D) txtBox.Text = CStr(5)
A
5. Which statement will display the words Hello World in a text box?
(A) txtBox.Text = Hello & World
(B) txtBox.Text = "Hello " & World
(C) txtBox.Text = Hello & " World"
(D) txtBox.Text = "Hello" & " World"
D
6. Which of the following expressions has as its value the value of strVar with its leading and
trailing spaces removed?
(A) strVar.Length
(B) strVar.ToUpper
(C) strVar.Ctrim
(D) strVar.Trim
D
10. Given the data assigned to the string variable str2 shown below, which of the following
statements will assign the value ALL to the string variable str1?
str2 = "WHEN ALL ELSE FAILS, READ THE DIRECTIONS"
(A) 8
(B) 9
(C) 8.5
(D) 17.00
A
(A) abcdeABCDE
(B) ABCDEABCDE
(C) eE
(D) EE
A
14. What will be the value of numVar when the following code is executed?
Dim strVar As String, numVar As Integer
strVar = "Now is the time for all good men"
numVar = strVar.IndexOf("the time for")
16. What will be displayed when the following lines are executed?
Dim x As Double = 2
'x = 3
txtBox.Text = CStr(x)
(A) 3
(B) 0
(C) 2
(D) None of the above
C
(A) 23
(B) 2 3
(C) 5
(D) Syntax error
A
22. The value of strVar.Length is the number of characters in the value of strVar. (T/F)
T
24. All comment statements must be placed at the beginning of a program. (T/F)
F
25. The statement lstBox.Items.Add("") clears all the text from the list box. (T/F)
F
27. The following statements assign the lowercase letters to the string variable alphabet. (T/F)
Dim alphabet As String
alphabet = abcdefghijklmnopqrstuvwxyz
F
28. The following statement is valid where dog and cat are variables of the same type. (T/F)
dog = cat
T
29. Option Explicit requires you to declare every variable before its use. (T/F)
T
30. With Option Strict On, a statement of the form intVar = dblVar is not valid. (T/F)
T
31. A statement of the form dblVar = intVar is a narrowing assignment statement. (T/F)
F
33. After the statement txtBox.Text = "" is executed, the text box will be clear and the
cursor will appear inside the text box. (T/F)
F
34. A string literal is a sequence of characters that is treated as a single entity. (T/F)
T
35. When declaring a variable of type String, you must specify a length for the string.(T/F)
F
37. The Trim method is used to remove all blank space before and after a string. (T/F)
T
39. The empty string is the same as a string that contains one space. (T/F)
F
40. A variable declared inside an event procedure is said to have local scope. (T/F)
T
41. A variable declared outside of an event procedure is said to have class-level scope. (T/F)
T
42. A variable declared inside an event procedure cannot have the same name as a variable
declared inside another procedure. (T/F)
F
43. When a variable declared in one event procedure has the same name as a variable declared
in another event procedure, any change to the value of one of the variables will affect the
value of the other variable. (T/F)
F
44. Write a statement that assigns the first character of the value of strVar1 to strVar2.
strVar2 = strVar1.Substring(0,1)
45. Write a statement that assigns the last character of the value of strVar1 to strVar2.
strVar2 = strVar1.Substring(strVar1.Length - 1, 1)
Section 3.3 Input and Output
3. Which statement prompts the user for a name and then assigns the name to the string
variable strName?
(A) strName = InputBox("What is your first name?", "First Name")
(B) strName = MessageBox.Show("What is your first name?", "First Name")
(C) InputBox("What is your first name?", "First Name") = strName
(D) MessageBox.Show "What is your first name?", "First Name" = strName
A
4. Suppose you are 20 years old, num is an integer variable, and the statement
num = 1 + CInt(InputBox("How old are you?"))
is executed and responded to? What will be the output of
txtBox.Text = num & " years old"
(A) $1234.567
(B) 1,234.57
(C) $1234.57
(D) $1,234.57
D
(A) 1234.568
(B) 1230
(C) 1,234.568
(D) 1,230
C
(A) 0.6666
(B) 0.6667
(C) 66.66%
(D) 66.6667%
D
10. Which of the following masks is appropriate for a masked text box into which the user will
enter a license plate consisting of two digits followed by 4 letters?
(A) &&LLLL
(B) &&&&&&
(C) 00LLLL
(D) None of the above
C
13. The line continuation character must be preceded with a space. (T/F)
T
14. When the Mask property of a masked text box is set to LL, at most two characters
(consisting of letters or spaces) can be entered into the masked text box. (T/F)
T
15. Write a statement that produces a message dialog box with the words "US Motto" in its title
bar and the message "E PLURIBUS UNUM".
MessageBox.Show("E PLURIBUS UNUM", "US Motto")
16. If TAX_RATE is a named constant of type Double, which of the following statements is
valid?
(A) TAX_RATE += 1
(B) dblVar = TAX_RATE + 1
(C) TAX_RATE = 2 * TAX_RATE
(D) All of the above
B
17. Which statement assigns the date of the first day of the year 2014 to the Date variable
firstDay?
(A) firstDay = 1/1/2014
(B) firstDay = "1/1/2014"
(C) firstDay = &1/1/2014&
(D) firstDay = #1/1/2014#
D
19. Which statement assigns today's date to the Date variable currently?
(A) currently = #Now#
(B) currently = #Today#
(C) currently = Now
(D) currently = Today
D
20. If the value of the Date variable currently is the first day of 2011, then what is displayed by
the statement txtBox.Text = CStr(currently.AddMonths(1))?
(A) 1/2/2011
(B) 2/1/2011
(C) February 1, 2011
(D) Tuesday February 1, 2011
B
22. The value assigned to a class-level named constant can be changed in any procedure. (T/F)
F