Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Name___________________________________
MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.
1) An algorithm is defined as 1)
A) a logical sequence of steps that solve a problem.
B) a tool that designs computer programs and draws the user interface.
C) a tempo for classical music played in a coda.
D) a mathematical formula that solves a problem.
3) Suppose in the very early stages of the problem-solving process, your supervisor wants you to 3)
show her the relationships between the various processes that will be needed to solve the
problem. The best way to do this would be to use
A) a flowchart. B) pseudocode.
C) a sample program. D) a top-down chart.
6) "Desk-checking" refers to 6)
A) the continual problem programmers have with losing things.
B) testing an algorithm at the flowchart stage using several different kinds of data.
C) having a fellow programmer read your pseudocode to be sure it is understandable.
D) timing a program to see how fast it completes its tasks.
1
9) What does the circle flowchart symbol represent? 9)
A) process
B) input/output
C) connector
D) terminal
E) decision
10) The process of finding and correcting errors in a program is called 10)
A) pseudocoding. B) debugging.
C) development cycles. D) algorithms.
11) A graphical depiction of the logical steps to carry out a task and show how the steps relate to 11)
each other is called a(n)
A) hierarchy chart. B) algorithms.
C) flowchart. D) pseudocode.
14) What does the "rectangle with rounded sides" flowchart symbol represent? 14)
A) process
B) input/output
C) predefined process
D) decision
E) start/stop
15) Which of the following actions cannot be done with a mouse? 15)
A) Hover
B) Double-click
C) Click
D) Drag
E) Erase
16) Which of the following types of charts shows only the relationships between general program 16)
tasks without showing specific modules or directions for data flow?
A) flowchart B) top-down chart
C) both A and B D) neither A nor B
2
17) If you are writing a program that needs to repeat a series of calculations, what programming 17)
structure should you use to repeat the calculations?
A) decision structure B) looping structure
C) unconditional branching D) sequence structure
18) Which of the following is NOT considered to be one of the three basic operations of a computer? 18)
A) processing B) input C) store D) output
21) Which one of the following is NOT one of the three basic types of statement structures? 21)
A) loop B) decision C) input/output D) sequence
22) Which of the following is the proper order of procedures used in the problem-solving process? 22)
A) design, analysis, coding, testing
B) design, testing, analysis, coding
C) analysis, design, testing, coding
D) analysis, testing, design, coding
E) analysis, design, coding, testing
23) Which of the following is NOT a main component of a personal computer? 23)
A) microprocessor
B) disk drive
C) receiver
D) monitor
E) keyboard
25) What is the standard convention for the extension of a text file? 25)
A) .TEXT B) .DATA C) .DOC D) .TXT
26) Which of the following statements sets the words on a button to "Push Me"? 26)
A) btnButton.Name = "Push Me" B) btnButton.Text = Push Me
C) btnButton = "Push Me" D) btnButton.Text = "Push Me"
3
27) A user action such as clicking a button is called 27)
A) a property. B) an event. C) a procedure. D) an accident.
28) Programming in VB 2008 is different from many other programming environments because first 28)
you should
A) name the buttons. B) input the data.
C) write the code. D) draw the user interface.
29) Visual Basic responds to events using which of the following? 29)
A) a property B) a form procedure
C) a code procedure D) an event procedure
30) The Properties window plays an important role in the development of Visual Basic applications. 30)
It is mainly used
A) to allow the developer to graphically design program components.
B) to change how objects look and feel.
C) to set program related options like Program Name, Program Location, etc.
D) when opening programs stored on a hard drive.
33) What would be a good name for a text box to hold a person's first name? 33)
A) txtFirstName B) First Name
C) txt First Name D) FirstName
34) IntelliSense is a technology built into Visual Basic that assists the programmer by 34)
A) allowing the programmer to edit object properties from inside the code window.
B) automatically displaying the methods and properties available to a control.
C) automatically inserting text and words that have similar meaning to those currently being
entered by the programmer.
D) replacing misspelled words with the correct spelling as soon as the programmer presses
the Enter key.
35) Which of the following steps specifies P as the access key for a button? 35)
A) Set the Text property to &Com_pute. B) Set the Text property to Com&pute.
C) Set the Text property to comPute. D) Set the Text property to Com_pute.
36) Which of the following is not a submenu of the Format menu? 36)
A) Center in Form B) Make Same Size
C) Align D) Widen
4
37) What effect will the following statement have? 37)
lblOne.Visible = False
A) Enable lblOne. B) Make lblOne invisible.
C) Delete lblOne. D) It is not a valid Visual Basic statement.
38) What property of controls tells the order they receive the focus when the tab key is pressed 38)
during run time?
A) Focus order B) Focus number C) Control order D) Tab index
40) What property of a control determines whether the control can receive the focus during run 40)
time?
A) Focus B) TabOrder C) TabIndex D) TabStop
41) In Visual Basic, tooltips assist by showing a small caption about the purpose of each icon on the 41)
Toolbar. How do you make a tooltip appear?
A) Position the mouse pointer over the icon for a few seconds, the tooltip will appear.
B) Right click the Toolbar icon, select purpose from the available options.
C) Hold your Alt key, then click the appropriate Toolbar icon to display its purpose.
D) Hold your shift key, then click the appropriate Toolbar icon to display its purpose.
42) What feature in Visual Basic allows you to make more room on your screen by temporarily 42)
minimizing certain windows?
A) Expert-View B) Auto Minimize
C) Help D) Auto Hide
43) What keyboard shortcut allows you to run the current program? 43)
A) F4 B) F5 C) F6 D) F7
44) What is the tab index of the first object placed on a form? 44)
A) 0 B) 1
C) First D) None of the above
46) Which of the following is not one of the three steps used to create a Visual Basic program? 46)
A) Create the interface. B) Specify the methods.
C) Set the properties of the object. D) Write the code.
47) What of the following is a correct statement for specifying the words to appear in the title bar of 47)
Form1?
A) Me.Caption = "My Text" B) Form1.TitleBar = "My Text"
C) Form1.Text = "My Text" D) Me.Text = "My Text"
5
48) When a Visual Basic program is running, the user can move from one control to another using 48)
the keyboard by pressing the
A) Space bar. B) Backspace key.
C) Enter key. D) Tab key.
49) Which of the following properties determines the words appearing in a form's title bar? 49)
A) Text B) Title C) Name D) Caption
50) Sizing Handles make it very easy to resize virtually any control when developing applications 50)
with Visual Basic. When working in the Form Designer, how are these sizing handles
displayed?
A) a rectangle with small squares around your control
B) a 3-D outline around your control
C) a rectangle with 4 arrows, one in each corner, around your control
D) None of the above
51) Which of the following statements specifies that the color of the text in txtBox be red? 51)
A) txtBox = Color.Red B) txtBox.Text = Color.Red
C) txtBox.ForeColor = Red D) txtBox.ForeColor = Color.Red
52) What will be displayed when the following lines are executed? 52)
Dim x As Double = 2
Dim y As Double = 3
Dim fmtStr As String = "{0,-5}{1, -5}"
lstOutput.Items.Add("1234567890")
lstOutput.Items.Add(String.Format(fmtStr, x, y))
A) 1234567890 B) 1234567890 C) 1234567890 D) 1234567890
23 2 3 2 3 2 3
54) What character is used to signify the beginning of a comment statement? 54)
A) apostrophe B) backslash
C) asterisk D) exclamation mark
56) What is the correct syntax for displaying the value of the String variable myString in a text box? 56)
A) txtBox.Text = myString B) txtBox.Text = "myString"
C) txtBox.Text.myString D) txtBox.Text = Str(myString)
6
57) Which declaration statement is used when you want to read data from the file DATA.TXT? 57)
A) Dim IO.File.OpenText("DATA.TXT")
B) Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
C) Dim DATA.TXT As IO.File.OpenText
D) Dim sr As IO.StreamReader = IO.File.OpenText(DATA.TXT)
58) What will be displayed when the following lines are executed? 58)
Dim fmtStr As String = "{0,-4:C0}{1, 6:P1}"
lstBox.Items.Add("123456789012")
lstBox.Items.Add(String.Format(fmtStr, 2.25, 0.375))
A) 123456789012 B) 123456789012
$2.00 37 % $2 0.375 %
C) 123456789012 D) 123456789012
$2 37.5 % $2.00 37.5%
59) What will be the contents of the variable x after the following statement is executed? 59)
x = Math.Sqrt(((9 + 7) / (4 * 2)) + 2)
A) 1
B) 2
C) 3
D) 4
E) None of the above
60) What will be displayed when the following lines are executed? 60)
Dim a, b, c As String
a = "THE WHOLE"
b = "PART"
c = a.Substring(CInt(Math.Sqrt(4)), b.Length)
txtBox.Text = CStr(c)
A) E WH B) HE W
C) 6 D) THE WHOLE PART
62) The joining of two strings together to form a new string is called 62)
A) substrings. B) compaction.
C) concatenation. D) addition.
63) Suppose the Double variable num has the value 123.4567. What value will the following 63)
statement assign to num?
num = Math.Round(num, 2)
A) 123.4567 B) 123.45 C) 123.457 D) 123.46
64) Which statement will assign the words "Hello World" to a text box? 64)
A) txtBox.Text = "Hello" & " World"
B) txtBox.Text = Hello & World
C) txtBox.Text = Hello & " World"
D) txtBox.Text = "Hello " & World
7
65) What is the value of ("12/15/09").Substring(3,2)? 65)
A) /15/ B) /15 C) 12/15/96 D) 15
67) Give a declaration statement for the format string fmtStr that will produce the output 67)
1234567890
a bc
when the following lines of code are executed.
lstOutput.Items.Add("1234567890")
lstOutput.Items.Add(String.Format(fmtStr, "a", "bc"))
A) Dim fmtStr As String = "{0,4}{1,4}"
B) Dim fmtStr As String = "{0,-4}{1,-4}"
C) Dim fmtStr As String = "{0,4}{1,-4}"
D) Dim fmtStr As String = "{0,-4}{1,4}"
69) Suppose you are 20 years old, num is an integer variable, and the statement 69)
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) 1 + "How old are you?" B) 21 years old
C) 20 years old D) Syntax error
70) The type of error that is normally spotted by the Code Editor is 70)
A) run-time. B) user. C) syntax. D) logical.
71) Which statement can be used to clear the contents of a text box? 71)
A) txtBox.Text = "" B) txtBox.Empty = True
C) txtBox = "" D) txtBox.Wipe()
72) Which of the following arithmetic operations has the highest level of precedence? 72)
A) */ B) +- C) ^ D) ( )
73) Suppose the first two lines of the file DATA.TXT contain the strings Clint and 1930. What is 73)
displayed by the following lines of code?
Dim name As String, birthYear As Integer
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
name = sr.ReadLine
birthYear = CInt(sr.ReadLine)
txtBox.Text = "In 2010, " & name & " will be " & (2010 — birthYear)
sr.Close()
A) In 2010, "Clint" will be 80
B) In 2005, Clint will be 2010 — 1930
C) In 2010, Clint will be 80
D) Clint, 1930
8
74) The following statement contains what type of error? 74)
txtAverage.Txt = CStr(CDbl(txtNum1.Text) + CDbl(txtNum2.Text) / 2)
A) a logic error only B) a syntax error only
C) both a syntax error and a logic error D) no errors
76) Suppose that the selector in a Select Case block is the string variable myVar. Which of the 76)
following is NOT a valid Case clause?
A) Case (myVar.Substring(0, 1) B) Case "Adams"
C) Case "739" D) Case myVar.Length
77) Which of the following is a valid Visual Basic conditional statement? 77)
A) (2 < n) Or (n < 5) B) 2 < n Or < 5
C) 2 < n Or 5 D) 2 < n < 5
78) Different items appearing in the same value list of a Select Case block must be separated by a 78)
________.
A) semi colon B) pair of quotation marks
C) colon D) comma
79) What will be displayed by the following program when the button is clicked? 79)
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
80) Constructs in which an If block is contained inside another If block are called 80)
A) sequential If blocks. B) nested If blocks.
C) multi-If blocks. D) None of the above
9
81) What is the problem (if any) with the following Select Case block which is intended to determine 81)
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) There is nothing wrong.
B) Everyone will get in free at the child rate.
C) The Case Is statements have bad syntax.
D) The output will always be "Entry error."
82) Asc("A") is 65. What is displayed by txtBox.Text = Chr(65) & "BC"? 82)
A) 656667 B) ABC
C) A BC D) Not enough information is available
83) A(n) ________ allows a program to decide on a course of action based on whether a certain 83)
condition is true or false.
A) Else block B) And block C) Or block D) If block
84) What will be the output of the following program when the button is clicked? 84)
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
10
85) What will be the output of the following program when the button is clicked? 85)
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) 0 B) 3 C) 6 D) No output
86) In a Select Case block, if more than one Case clause matches the selector, 86)
A) all of the statements associated with each matching Case clause will be executed.
B) only the statements associated with the last matching Case clause will be executed.
C) only the statements associated with the first matching Case clause will be executed.
D) the program will malfunction and stop.
87) Which value for x would make the following condition true: (x >= 5) And (x <= 6) 87)
A) x is equal to 7 B) x is equal to 5
C) x is equal to 5.001 D) B and C
88) The three main logical operators are ________, ________, and ________. 88)
A) False, And, True B) Or, Not, If
C) And, Not, If D) And, Or, Not
89) Which of the following expressions has as its value the words "Hello World" surrounded by 89)
quotation marks?
A) Chr(34) & Hello World & Chr(34)
B) "Hello World"
C) Chr(34) & "Hello World" & Chr(34)
D) Chr(34) & "Hello World"
90) Which value for x would make the following condition true: x >= 5 90)
A) x is equal to 7 B) x is equal to 5.001
C) x is equal to 5 D) All of the above
91) When using the logical operator "Or", what part of the expression must be true? 91)
A) only the right part B) only the left part
C) either the left or right part, but not both D) either the left or right part
92) Which Case clause will be true whenever the value of the selector in a Select Case block is 92)
between 1 and 5 or is 8?
A) Case 1 To 5; 8 B) Case 1 To 5, 8 C) Case 1 To 8 D) Case 1 To 8, 5
11
94) What type of items are valid for use in the value list of a Case clause? 94)
A) expressions B) variables
C) literals D) All of the above
95) Which Case clause will be true whenever the value of the selector in a Select Case block is 95)
greater than or equal to 7?
A) Case Is >7 B) Case Is = 8 C) Case Is <= 8 D) Case Is >= 7
97) What will be displayed in the list box when the following code runs? 97)
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) W and Y will be displayed if the value of num is 7.
B) Z will always be displayed.
C) W, X and Y will be displayed if the value of num is 6.
D) Z can never be displayed.
98) A program is said to be ________ if it meets modern standards of program design. 98)
A) top-down B) structured C) modular D) logical
99) The arguments appearing in a Call statement must match the parameters in the appropriate Sub 99)
or Function header in all but one of the following ways. Which one?
A) names of arguments B) number of arguments
C) data type of arguments D) order of arguments
101) Which of the following logical structures should not be used in structured programming? 101)
A) Selection B) Sequence
C) Unconditional branching D) Looping (iteration)
102) Breaking up a large problem into smaller subproblems is called ________. 102)
A) transcribed modules B) refined modules
C) transcribed refinement D) stepwise refinement
12
103) Which of the following is NOT considered part of a good top-down design chart? 103)
A) Modules should be as independent of each other as possible.
B) Modules should proceed from general to specific as you read down the chart.
C) The design should be readable.
D) A module should accomplish as many tasks as possible.
104) The process of transmitting values to a Sub procedure is known as ________. 104)
A) passing B) referencing C) evaluating D) conveying
105) Items appearing in the parentheses of a Call statement are known as ________. 105)
A) Call variables B) Call strings C) arguments D) parameters
106) What will be the output when the button is clicked? 106)
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim first, middle, last As String
first = "Augusta"
middle = "Ada"
last = "Byron"
Initials(first, middle, last)
End Sub
Sub Initials(ByVal c As String, ByVal b As String, _
ByVal a As String)
Dim theInitials As String
theInitials = a.Substring(0, 1) & b.Substring(0, 1) & _
c.Substring(0, 1)
txtBox.Text = theInitials
End Sub
A) ABA B) AAB C) abc D) BAA
107) Suppose a variable is passed by value to a parameter of a Sub procedure, and the parameter has 107)
its value changed inside the Sub procedure. What will the value of the variable be after the Sub
procedure has executed?
A) It will retain the value it had before the call to the Sub procedure.
B) It will have the newly modified value from inside the Sub procedure.
C) Its value can't be determined without more information.
D) None of the above
13
109) Based on what it returns, what would be a better name for the function "Mystery" in the 109)
following program?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim sentence As String, result As String
sentence = "Socrates is a man."
result = Mystery(sentence)
txtBox.Text = result
End Sub
Function Mystery(ByVal sentence As String) As String
Dim position As Integer
position = sentence.IndexOf(" ")
Return sentence.Substring(0, position)
End Function
A) DoesNothing
B) LastLetter
C) LastWord
D) FirstLetter
E) FirstWord
111) What will be the output of the following program when the button is clicked? 111)
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim var1, var2, var3, num As Integer
var1 = 2
var2 = 4
var3 = 6
Add(num)
txtBox.Text = CStr(num)
End Sub
Sub Add(ByRef num As Integer)
Dim var1, var2, var3 As Integer
num = var1 + var2 + var3
End Sub
A) 12 B) 6
C) 0 D) None of the above
14
112) What will be the output of the following program when the button is clicked? 112)
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim word, result As String
word = "Benjamin"
result = Rotate(word)
result = Rotate(result & word)
result = Rotate(result)
txtBox.Text = result
End Sub
Function Rotate(ByVal var As String) As String
Dim varlength As Integer
varlength = var.Length
Return var.Substring(1) & var.Substring(0, 1)
End Function
A) BenjaminBenjamin B) njaminBe
C) jaminBBenjaminen D) None of the above
113) Variables appearing in the header of a Function procedure are called ________. 113)
A) coordinates B) arguments
C) values of the function D) parameters
114) Which one of the following is true about arguments and parameters? 114)
A) Parameters appear in Call statements; arguments appear in Sub statements.
B) They are completely unrelated in a program.
C) Arguments appear in Call statements; parameters appear in Sub statements.
D) They are synonymous terms.
115) Suppose the variable myName is declared in a Dim statement in two different Sub procedures. 115)
Which statement is true?
A) The program will malfunction when it is executed.
B) The two variables will be local to their respective Sub procedures.
C) When the value of myName is changed in one Sub procedure, it will also be changed in the
other Sub procedure.
D) Visual Basic's smart editor will alert you that this is an error before the program is
executed.
116) Which of the following is NOT a reason for using procedures? 116)
A) They make it possible for a team of people to work together on a single program.
B) They make a program run faster.
C) They can be reused easily.
D) They break a complex problem down into smaller pieces.
117) Which of the following names would be best for the following Function (called NoName)? 117)
Function NoName(ByVal number As Double) As Double
Return number ^ 3 + number ^ 3
End Function
A) CubeAndSquare B) DoubleAndCube
C) SquareAndCube D) CubeAndDouble
118) A variable that keeps track of whether a certain situation has occurred is called 118)
A) a flag. B) a switch.
C) an accumulator. D) a counter.
15
119) How many lines of output are produced by the following program segment? 119)
For i As Integer = 1 To 3
For j As Integer = 1 To 3
For k As Integer = i to j
lstBox.Items.Add("Programming is fun.")
Next
Next
Next
A) 8 B) 9 C) 10 D) 11
120) Which of the following program segments will sum the eight numbers read from the file? 120)
Assume the text file has been open for input with the StreamReader sr.
A) For k As Integer = 1 To 8 B) For k As Integer = 1 To 8
a = CDbl(sr.ReadLine) a = CDbl(sr.ReadLine)
s += a s += 1
Next Next
C) For k As Integer = 1 To 8 D) For k As Integer = 1 To 8
a = CDbl(sr.ReadLine) s = CDbl(sr.ReadLine)
a += s s += k
Next Next
121) Given the following partial program, how many times will the statement 121)
lstBox.Items.Add(j + k + m) be executed?
For j As Integer = 1 To 4
For k As Integer = 1 To 3
For m As Integer = 2 To 10 Step 3
lstBox.Items.Add(j + k + m)
Next
Next
Next
A) 60
B) 24
C) 10
D) 36
E) None of the above
122) What is the data type of the variable num if Option Infer is set to On and the statement Dim num 122)
= 7.0 is executed?
A) String B) Integer C) Boolean D) Double
123) Suppose the days of the year are numbered from 1 to 365 and January 1 falls on a Tuesday as it 123)
did in 2008. What is the correct For statement to use if you want only the numbers for the
Thursdays in 2008?
A) For i As Integer = 1 to 365 Step 3
B) For i As Integer = 3 to 365 Step 7
C) For i As Integer = 3 To 365 Step 6
D) For i As Integer = 365 To 1 Step -7
124) In a For statement of the form shown below, what is the default step value when the "Step c" 124)
clause is omitted?
For i As Integer = a To b Step c
A) 1 B) the same as a C) 0 D) the same as b
16
125) Which of the following are valid for an initial or terminating value? 125)
A) info.Length, where info is a String variable
B) a numeric expression
C) a numeric literal
D) All of the above
126) What will be displayed by the following program when the button is clicked? 126)
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim a As String, n, c As Integer
a = "HIGHBACK"
n = CInt(Int(a.Length / 2))
c = 0
For k As Integer = 0 To n — 1
If a.Substring(k, 1) > a.Substring(7 — k, 1) Then
c += 1
End If
Next
txtBox.Text = CStr(c)
End Sub
A) 1 B) 2 C) 3 D) 4 E) 5
128) If the loop is to be executed at least once, the condition should be checked at the ________. 128)
A) middle of the loop B) bottom of the loop
C) top of the loop D) Nothing should be checked.
129) What is wrong with the following program that intends to calculate the average of student test 129)
scores? Assume that the file DATA.TXT has several numeric entries.
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim total, score, average, numItems As Double
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
total = 0
numItems = 0
score = CDbl(sr.ReadLine)
Do While sr.Peek <> -1
total += score
numItems += 1
score = CDbl(sr.ReadLine)
Loop
sr.Close()
average = total / numItems
txtBox.Text = CStr(average)
End Sub
A) The accumulator does not add the last score in the file.
B) The variable score is not initialized.
C) A division by zero error could occur when computing the average.
D) There is nothing wrong with the program.
17
130) In the following code segment, what role does the variable check serve? 130)
Dim counter As Integer, check As Boolean
Do While counter < 20
counter += 1
If counter = 10 Then
check = True
End If
Loop
A) loop control variable B) counter
C) flag D) accumulator
131) Which loop computes the sum of 1/2 + 2/3 + 3/4 + 4/5 + … + 99/100? 131)
A) For d As Integer = 2 To 99 B) For q As Integer = 100 To 1
s = 1 / d + d / (d + 1) s += (q + 1) /q
Next Next
C) For x As Integer = 1 To 100 D) For n As Integer = 1 To 99
s += 1 / (x + 1) s += n / (1 + n)
Next Next
132) ________ can be used to determine when the end of a text file has been reached. 132)
A) The Peek method B) A flag
C) A nested loop D) An accumulator
133) What will be displayed by the following program when the button is clicked? 133)
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim s As Double
s = 0
For k As Integer = 1 To 5
If k / 2 = Int(k / 2) Then
s +=k
End If
Next
txtBox.Text = CStr(s)
End Sub
A) 15 B) 6 C) 12 D) 9
134) When the odd numbers are added successively, any finite sum will be a perfect square (e.g., 1 + 3 134)
+ 5 = 9 and 9 = 3^2). What change must be made in the following program to correctly
demonstrate this fact for the first few odd numbers?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim oddNumber As Integer
Dim sum As Integer = 0
For i As Integer = 1 To 9 Step 'Generate first few odd numbers
oddNumber = i
For j As Integer = 1 To oddNumber Step 'Add odd numbers
sum += j
Next
lstBox.Items.Add(sum & " is a perfect square.")
Next
End Sub
A) Reset sum to zero immediately before the second Next statement."
B) Reset sum to zero immediately before the first Next statement."
C) Change the Step size to 1 in the first For statement.
D) Move oddNumber = i inside the second For loop.
18
135) What will be displayed by the following program when the button is clicked? 135)
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim letter As String, s As String = ""
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
letter = sr.ReadLine
Do While letter <> "q"
s = letter & s
letter = sr.ReadLine
Loop
txtBox.Text = s
End Sub
The seven lines of the file DATA.TXT contain the following data: n, o, p, q, r, s, t.
A) rst B) nop C) pon D) qpon
136) Assume the array num() has been filled as shown. What is the output of the following program 136)
segment?
A) 3 B) 9 C) 8 D) 7 E) 4
137) In the ordered array declared with the statement below, the value of the element namfriend(0) is 137)
equal to that of which of the other following elements?
Dim namfriend() As String = {"Fred", "Fred", "fred", "fred"}
A) namfriend(1 B) namfriend(2) C) namfriend(3) D) namfriend(4)
138) How many comparisons will be made in the first pass of a bubble sort of 6 items? 138)
A) 5 B) 4
C) 6 D) depends on the elements to be sorted
139) After the following Dim statement is executed, how many subscripted variables called myvar(i) 139)
will be available?
Dim myVar(7) As Double
A) 0 B) 1 C) 8 D) 9
19
140) What is the output of the following program segment? 140)
Dim antonym(7) As String
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
For i As Integer = 0 To 6 Step 2
antonym(i) = sr.ReadLine
antonym(i + 1) = sr.ReadLine
Next
sr.Close()
txtBox.Text = antonym(3)
Assume the twelve rows of the file DATA.TXT contain the following entries: big, small, black,
white, old, young, fast, slow, tall, short, hard, soft.
A) black B) small
C) white D) Subscript out of range
141) Each of the following represents a step in the bubble sort algorithm except one. Which of the 141)
following is not a step used in a pass through a list by the bubble sort algorithm?
A) On the final comparison of the first pass, the possible swap is between the next-to-last
and last items.
B) Compare the first and last items. If they are in the wrong order, swap them.
C) Compare the second and third items. If they are in the wrong order, swap them.
D) Compare the first and second items. If they are in the wrong order, swap them.
142) A program contains a form (Form1) with three text boxes (TextBox1, TextBox2, and TextBox3). 142)
The line
Dim txtBox(2) As TextBox
is placed in the Declarations section of the Code window. The three lines
txtBox(0) = TextBox1
txtBox(1) = TextBox2
txtBox(2) = TextBox3
are placed in the Form1_Load procedure for this program. Which of the following statements are
true about the three lines of code?
A) They assign the three text boxes to elements of the array txtBox().
B) They change the Text property for the three text boxes at run time.
C) These lines of code could have been placed in the Declarations section of the Code
window.
D) They create a control array with the name TextBox.
143) When using the bubble sort algorithm, which of the following is true about the number of passes 143)
used to sort a list?
A) The number of passes used is one more than the number of items to be sorted.
B) The number of passes used is one less than the number of items to be sorted.
C) The number of passes used is equal to the number of items to be sorted.
D) The number of passes used is equal to twice the number of items to be sorted.
144) When using the bubble sort algorithm, after the second pass through the list, which of the 144)
following will be true?
A) The first item only is guaranteed to be in its proper position.
B) The last item only is guaranteed to be in its proper position.
C) The last two items are guaranteed to be in their proper position.
D) The first two items are guaranteed to be in their proper position.
20
145) What is the output of the following program segment? 145)
Dim values(2), num, k As Integer
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
num = 0
For i As Integer = 0 To 2
values(i) = CInt(sr.ReadLine)
Next
For j As Integer = 1 To 3
k = CInt(sr.ReadLine)
num += values(k)
Next
txtBox.Text = CStr(num)
Assume the six rows of the file DATA.TXT contain the following entries: 2, 1, 3, 0, 0, 1.
A) 5 B) 6 C) 7 D) 8
146) Given the Dim statement below, which set of statements will initialize all elements of myArray() 146)
to 100?
Dim myArray(100) As Double
A) For i = 0 To 100
(i) = 100
Next
B) myArray = 100
C) myArray() is already initialized to 100 by the Dim statement.
D) For j = 0 to 100
myArray(j) = 100
Next
147) What is displayed in the list box by the following program segment? 147)
Dim phoneDir(50) As String, i As Integer
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
For j As Integer = 0 To 9 Step 3
phoneDir(j) = sr.ReadLine
phoneDir(j + 1) = sr.ReadLine
phoneDir(j + 2) = sr.ReadLine
Next
sr.Close()
lstBox.Items.Clear()
i = 1
Do While phoneDir(i) <> ""
lstBox.Items.Add(phoneDir(i))
i += 3
Loop
Assume the twelve rows of the file DATA.TXT contain the following entries: Fischer, John,
797-3456, Robinson, Max, 535-8657, Stanberg, Jennifer, 544-9080, Thompson, Meg, 436-2345.
A) John, Max, Jennifer, and Meg
B) Fischer, Robinson, Stanberg, and Thompson
C) 797-3456, 535-8657, 544-9080, and 436-2345
D) No output
148) Assume a binary search is looking for "Mankato" in the following list. Which city would be 148)
compared with "Mankato" first?
Akron Hartford Ithaca Seattle Tulsa
A) Ithaca B) Seattle C) Tulsa D) Hartford E) Akron
21
149) What names are displayed in the list box when the button is clicked? 149)
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim name(4) As String
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
For i As Integer = 0 To 4
name(i) = sr.ReadLine
Next
sr.Close()
lstBox.Items.Clear()
For i As Integer = 4 To 0 Step -2
lstBox.Items.Add(name(i))
Next
End Sub
Assume the five lines of the file DATA.TXT contain the following entries: Bach, Borodin, Brahms,
Beethoven, Britain.
A) Britain, Beethoven, Brahms, Borodin, and Bach
B) Bach, Borodin, Brahms, Beethoven, and Britain
C) Britain, Brahms, and Bach
D) Bach, Brahms, and Britain
150) A program contains a form (Form1) with four text boxes (TextBox1, TextBox2, TextBox3, and 150)
TextBox4). The line
Dim txtBox(3) As TextBox
appears in the Declarations section of the Code window. This line carries out which of the
following tasks?
A) It creates a new text box containing the number 3.
B) It establishes a maximum value of 3 for the value of any element in the txtBox() control
array.
C) It creates a control array with the name txtBox.
D) It creates a variable array with the name TextBox.
152) When merging sequential files without duplications, the last step in any algorithm should be to 152)
complete which of the following tasks?
A) Close all opened files.
B) Delete all items of data that remain in the ordered files once the files have been merged.
C) After there is no longer data in one of the ordered files, write out all remaining data in the
other file.
D) Index all opened files.
22
153) Identify the control variable in the following code block. 153)
Dim loopStart As Integer = 1
Dim message As String
Dim loopContinue As Integer = 1
Do While loopContinue <= 3
message = "The number is " & loopContinue
MessageBox.Show(message)
loopContinue += loopStart
Loop
A) loopStart B) loopContinue C) Integer D) message
155) When an exception is generated by a Visual Basic application, the default exception handler will 155)
A) restart the program.
B) display a dialog box that asks the user if they wish to restart the computer.
C) continue to execute the program.
D) terminate the program.
157) Assume the file ALPHABET.TXT contains 26 records, the lowercase letters of the alphabet in 157)
ascending order. What is stored in TARGET.TXT after the following code is executed?
Dim letter As String
Dim sr As IO.StreamReader = IO.File.OpenText("ALPHABET.TXT")
Do While sr.Peek <> -1
Dim sw As IO.StreamWriter = IO.File.CreateText("TARGET.TXT")
letter = sr.ReadLine
sw.WriteLine(letter)
sw.Close()
Loop
sr.Close()
A) z B) the alphabet in descending order
C) a D) the alphabet in ascending order
23
158) In which line of the following code does the break occur? 158)
Dim loopStart As Integer = 1
Dim message As String
Dim loopContinue As Integer = 1
Do While loopContinue <= 3
message = "The number is " & loopContinue
MessageBox.Show(message)
loopContinue += loopStart
Loop
A) Dim loopStart As Integer B) loopContinue += loopStart
C) End While D) Dim message As String
159) If included in a program as written here, which exception will the following code generate? 159)
Dim num1 As Integer, num2 As Integer = 1000000
num1 = num2 * num2
A) OverflowException B) InvalidCastException
C) NullReferenceException D) ArgumentOutOfRangeException
160) Which of the following is an example of how a filespec for a sequential file would be written 160)
within a Visual Basic application?
A) "C:\TEXT FILES\INCOME DATA.TXT"
B) "C:\TEXT FILES\INCOME DATA.*"
C) C:\TEXT FILES\INCOME DATA.TXT
D) "C\TEXT FILES\INCOME DATA.TXT"
161) Consider the following code. The Catch block of code will not be executed if the user enters 161)
which of the following when prompted?
Private Sub btnCalc_Click(...) Handles btnCalc.Click
Dim newNum, finalNum As Integer
Dim message, message1 As String
Try
newNum = CInt(InputBox("How old are you?"))
Catch
message = "That answer is not an Integer value."
MessageBox.Show(message)
newNum = 0
Finally
finalNum = newNum + 1
message1 = "Your age next year will be " & finalNum & "."
MessageBox.Show(message1)
End Try
End Sub
A) 0 B) 3000000000 C) one D) *
162) Which of the terms in the following line of code are named variables that could be replaced as 162)
long as all other references were also updated?
sr = IO.File.OpenText(fileName)
A) IO B) fileName C) OpenText D) File
24
164) Which of the following exceptions will be generated by trying to access a disk drive that doesn't 164)
contain a disk?
A) OverflowException B) IndexOutOfRangeException
C) NullReferenceException D) IO.DirectoryNotFoundException
165) Assume the file ALPHABET.TXT contains 26 records, the lowercase letters of the alphabet in 165)
ascending order. What happens when the following code is executed?
Dim letter As String
Dim sr As IO.StreamReader = IO.File.OpenText("ALPHABET.TXT")
Do While sr.Peek <> -1
letter = sr.ReadLine
Dim sw As IO.StreamWriter = IO.File.CreateText(letter.ToUpper &
".TXT")
sw.WriteLine(letter.ToUpper & ".TXT")
sw.Close()
Loop
sr.Close()
A) A "too many files open" error is produced.
B) An "invalid file name" error is produced.
C) A file called z is created containing all of the letters of the alphabet in lowercase.
D) Twenty-six files are created and named with one of the uppercase letters of the alphabet
and each containing only its own file name.
166) The following statement causes the Open dialog box to become visible on the form. 166)
OpenFileDialog1.ShowDialog()
After a file has been selected and the Open button is pressed, the value of
OpenFileDialog1.FileName
will be the file's filespec; this will include all of the following except
A) the file's extension. B) the file's date of creation.
C) the file's drive. D) the file's path.
In the following exercises assume the statement Dim gr As Graphics = picOutput.CreateGraphics has been
executed.
167) The distance from the top of the picture box to the top of the circle drawn by the statement 167)
gr.DrawEllipse(Brushes.Red, 10, 20, 40, 40) is.
A) 40 pixels B) 20 pixels C) 80 pixels D) 10 pixels
168) For a scroll bar, the value of the Value property is 168)
A) a number between the values of the SmallChange and LargeChange properties.
B) any number.
C) true or false.
D) a number between the values of the Minimum and Maximum properties.
169) Which of the following methods is used to load a new picture into a picture box control? 169)
A) picBox.Image = Image.FromFile(filespec)
B) picBox.Picture = filespec
C) picBox.Image = filespec
D) picBox.Picture = LoadPicture(filespec)
25
In the following exercises assume the statement Dim gr As Graphics = picOutput.CreateGraphics has been
executed.
170) The radius of the circle drawn by the statement gr.DrawEllipse(Brushes.Red, 10, 20, 170)
40, 40) is.
A) 80 pixels B) 40 pixels C) 20 pixels D) 10 pixels
171) When the user clicks on a check box control at run time, which one of the following events is 171)
triggered (in addition to the Click event)?
A) ControlAdded B) CheckedChanged
C) Invalidated D) StyleChanged
172) Which of the following techniques does NOT always toggle the checked and unchecked state of 172)
a check box control?
A) Press Alt+Access key (if an access key has been specified).
B) Set the Checked property equal to 1.
C) Press the spacebar when the square has the focus.
D) Click on the square or its caption with the mouse.
173) Which of the following steps turns off a timer control? 173)
A) Set the Interval property to zero. B) Make the timer control invisible.
C) Set the Enabled property to False. D) None of the above
In the following exercises assume the statement Dim gr As Graphics = picOutput.CreateGraphics has been
executed.
174) The center of the circle drawn by the statement gr.DrawEllipse(Brushes.Red, 10, 20, 174)
40, 40) has coordinates.
A) (20, 40) B) (40, 40) C) (30, 40) D) (10, 20)
175) The distance that the scroll box of a scroll bar will move when an arrow on the scroll bar is 175)
clicked is determined by
A) SmallChange. B) Maximum. C) LargeChange. D) Value.
In the following exercises assume the statement Dim gr As Graphics = picOutput.CreateGraphics has been
executed.
176) Give a statement that draws a red diagonal from the upper-left corner of the picture box to the 176)
lower-right corner.
A) gr.DrawLine(Pens.Red, 0, 0, picOutput.Width, picOutput.Height)
B) gr.DrawLine(Color.Red, 0, 0, picOutput.Width, picOutput.Height)
C) gr.DrawLine(Pens.Red, picOutput.Width, 0, 0, picOutput.Height)
D) gr.DrawLine(Pens.Red, 0, 0, picOutput.Height, picOutput.Width)
177) MenuStrip controls respond to which one of the following events? 177)
A) Change B) Click C) Load D) Double
26
178) Which of the following controls is not used to select an item from a list? 178)
A) OpenFileDialog B) ComboBox
C) Timer Control D) List Box
181) The following form of SQL command is classified as which of the four basic types of SQL 181)
requests?
SELECT * FROM Table1 INNER JOIN Table2 ON foreign field = primary field
WHERE criteria
A) Request I: show the records of a table in a specified order
B) Request IV: make available just some of the fields of either the basic table or joined table
C) Request II: show just the records that meet certain criteria
D) Request III: join the tables together (connected by a foreign key) and present the records
that meet certain criteria
182) The following form of SQL command is classified as which of the four basic types of SQL 182)
requests?
SELECT * FROM Table1 ORDER BY field1 DESC
A) Request III: join the tables together (connected by a foreign key) and present the records
B) Request IV: make available just some of the fields of either the basic table or joined table
C) Request II: show just the records that meet certain criteria
D) Request I: show the records of a table in a specified order
184) The requirement that no record may have a null primary key and that entries for primary keys 184)
be unique is called the
A) Rule of Primary Keys. B) Rule of Referential Integrity.
C) Rule of Entity Integrity. D) Rule of Null Values.
27
185) Which one of the following statements is true about primary keys? 185)
A) A primary key is used to uniquely identify records in a table.
B) A column of names is usually a good choice for use as a primary key.
C) Social Security numbers are never used as a primary key.
D) Only a single record can be used as a primary key.
187) Which of the following terms is defined as two or more interdependent tables? 187)
A) Rule of Referential Integrity B) SQL
C) relational database D) join
188) The following form of SQL command is classified as which of the four basic types of SQL 188)
requests?
SELECT field1, field2, ..., fieldN FROM Table1 WHERE criteria
A) Request II: show just the records that meet certain criteria
B) Request IV: make available just some of the fields of a table
C) Request I: show the records of a table in a specified order
D) Request III: join the tables together (connected by a foreign key) and present the records
189) Which one of the following statements is NOT true about tables? 189)
A) Each column of a table represents a field.
B) Each record in a table contains unrelated collections of fields.
C) A table is a rectangular array of data.
D) Each row of a table represents a record.
190) Which of the following is used to insure that each value for a foreign key also appears as a value 190)
for the primary key in any related table?
A) the Rule of Referential Integrity B) SQL
C) the Join statement D) a relational database
191) When creating a new application in Visual Basic, you are asked to supply a name for the 191)
program. If you do not specify a name, a default name is used. What is this default name?
A) Wapplication followed by a number
B) WindowsApplication
C) Application followed by a number
D) WindowsApplication followed by a number
192) Which property is available for most controls that allows you to hide/unhide them either 192)
manually by setting the property or by setting it during run time via code?
A) Clear B) Refresh C) View-Control D) Visible
28
193) When will the following event procedure be executed? 193)
Private Sub txtBox_TextChanged(...) Handles txtBox.TextChanged
A) when text is modified inside the text box
B) when text is deleted from the text box
C) when text is added to the text box
D) All of the above
194) Which of the following statements will place "Greetings" in the title bar of a form? 194)
A) Me.Title = "Greetings" B) Me.Text = "Greetings"
C) Me.Heading = "Greetings" D) Me.Name = "Greetings"
195) Visual Basic access keys are created by using which symbol in a button's Text property? 195)
A) @ B) % C) & D) #
196) The Font dialog box allows you to select different Fonts, their style, their size, and some other 196)
special effects. How do you bring up this Font dialog box?
A) Double-click the control, and select Font Property.
B) In the Properties window, click the ellipsis (…) on the right side of the settings box for the
Font property.
C) Right-click the control, and select Font Property.
D) None of the above
198) Which of the properties in a control's list of properties is used to give the control a meaningful 198)
name?
A) ControlName B) Name C) ContextMenu D) Text
201) Which of the following statements declare the variables a and b as type Integer? 201)
A) Dim a, b B) Dim a & b As Integer
C) a = 0: b = 0 D) Dim a, b As Integer
29
203) After the statement 203)
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
has been executed, which of the following statements will close the file?
A) Close sr B) sr.Close()
C) "DATA.TXT".Close() D) Close "DATA.TXT"
204) Which of the following expressions has as its value the value of strVar with its leading and 204)
trailing spaces removed?
A) strVar.Length B) strVar.Trim
C) strVar.ToUpper D) strVar.Ctrim
205) Which of the following statements removes all text from lstBox? 205)
A) lstBox.Items.Add("") B) lstBox.Items.Clear()
C) lstBox.Text.Clear() D) lstBox.Clear()
206) What will be displayed when the following lines are executed? 206)
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) 9 B) 10
C) 4 D) None of the above
207) Which of the following expressions will yield the string "John Doe", where name1 = "John Blake" 207)
and name2 = "Janet Doe"?
A) name1.Substring(0, 4) & name2.Substring(6, 8)
B) name1.Substring(0, 5) & name2.Substring(6, 3)
C) name1.Substring(0, 4) & name2.Substring(0, 3)
D) None of the above
210) Which value for x would make the following condition true: Not (x >= 5) 210)
A) x is equal to 4 B) x is equal to 7
C) x is equal to 5.001 D) All of the above
30
211) What will be displayed when the button is clicked? 211)
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim num As Double = 9
Dim sqrRoot As Double
If num < 0 Then
MessageBox.show("Cannot find square root-result set to zero",
"Error")
sqrRoot = 0
Else
sqrRoot = Math.Sqrt(Num)
End If
txtBox.Text = CStr(sqrRoot))
End Sub
A) 0 B) 6
C) 3 D) An error will occur.
212) Which of the following is not a logical operator in Visual Basic? 212)
A) Or B) Not C) Then D) And
213) What will be the output of the following program when the button is clicked? 213)
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) Syntax error
C) Drug Enforcement Agency
D) Unknown acronym. Sorry.
31
216) What word(s) will appear in the list box when the button is clicked? 216)
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim num As Integer = 5
If num = 2 Then
lstBox.Items.Add("Two")
ElseIf num > 3 Then
lstBox.Items.Add("Great")
ElseIf num = 5 Then
lstBox.Items.Add("Equal")
End If
End Sub
A) Great and Equal B) Two, Great, and Equal
C) Equal D) Great
217) What will be the output of the following program when the button is clicked? 217)
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) Washington B) WashWashington
C) WASHINGTONWashington D) No output
218) What will be the output of the following lines of code? 218)
Dim phrase As String = "A penny saved is worth nothing."
If phrase.IndexOf("pen") <> -1 Then
txtBox.Text = CStr(phrase.IndexOf("pen"))
Else
txtBox.Text = CStr(-1)
End If
A) 0
B) pen
C) 2
D) A penny saved is worth nothing.
219) What will be the output of the following program when the button is clicked? 219)
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim word As String
word = "hairbrush"
Decapitate ((word))
txtBox.Text = word
End Sub
Sub Decapitate(ByRef word As String)
'Chop the first letter off the word.
word = word.Substring(1)
End Sub
A) airbrush B) hairbrus C) h D) hairbrush
32
220) The declaration statement for a class-level variable should be placed ________. 220)
A) inside an event procedure
B) anywhere in the program region, except inside a procedure
C) inside a general procedure
D) above the statement Public Class frmName
221) What will be the output of the following program when the button is clicked? 221)
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim num As Integer = 10
DisplayMult(num)
num = 5
DisplayMult(num)
num = 2
DisplayMult(num)
End Sub
Sub DisplayMult(ByVal num As Integer)
If num <= 3 Then
txtOutput.Text &= CStr(3 * num)
Else
If num > 7 Then
txtOutput.Text &= CStr(7 * num)
End If
End If
End Sub
A) 7014 B) 706 C) 30614 D) No output
222) A variable that is visible to every procedure in a form's code without being passed is called a 222)
________ variable.
A) public B) class-level C) local D) global
223) What is the output of the following program when the button is clicked? 223)
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim a, b As String
txtBox.Clear()
a = "A"
b = "B"
PrintWords(a, b)
PrintWords(b, a)
End Sub
Sub PrintWords(ByVal a As String, ByVal b As String)
txtBox.Text &= a & b
End Sub
A) abba B) ab ba C) AB BA D) ABBA
224) If TAX_RATE is a named constant of type Double, which of the following statements is valid? 224)
A) TAX_RATE = 2 * TAX_RATE B) dblVar = TAX_RATE + 1
C) TAX_RATE += 1 D) All of the above
225) Variables declared inside a procedure are said to have ________. 225)
A) class-level scope B) local scope
C) procedure-level scope D) None of the above
33
226) What will be the output of the following program when the button is clicked? 226)
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim word1, word2, word3, result As String
word1 = "The"
word2 = "English"
word3 = "Channel"
CatWords(word1, word2, word3, result)
txtBox.Text = result
End Sub
Sub CatWords(ByVal var1 As String, ByVal var2 As String, _
ByVal word3 As String, ByRef final As String)
final = var1 & var2 & word3
End Sub
A) The English Channel B) TheEnglishChannel
C) TheEnglish D) No output
229) When Visual Basic executes a Do While loop it first checks the truth value of the ________. 229)
A) pass B) condition C) loop D) statement
230) What is the value of j after the end of the following code segment? 230)
For j As Integer = 1 to 23
lstBox.Items.Add("The counter value is " & j)
Next
A) 22 B) 24
C) 23 D) j no longer exists
231) A For...Next loop with a positive step value continues to execute until what condition is met? 231)
A) The control variable is less than or equal to the terminating value.
B) The control variable is greater than the terminating value.
C) The control variable is less than the terminating value.
D) The control variable is equal to or greater than the terminating value.
34
233) What will be the output of the following program when the button is clicked? 233)
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim vowel As String
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
Do While sr.Peek <> -1
vowel = sr.ReadLine
txtBox.Text &= vowel & ", "
Loop
sr.Close()
txtBox.Text &= "and sometimes y"
End Sub
Assume the five lines of the file DATA.TXT contain the following data: a, e, i, o, u.
A) a, and sometimes y
B) a, e, i, o, u, and sometimes y
C) a, e, i, o, u
D) and sometimes y
234) What will be the value of phrase(1) after the following code is executed? 234)
Dim place, i As Integer
Dim character, sentence, phrase(9) As String
sentence = "Every path hath a puddle."
place = 0
i = 0
character = sentence.Substring(place, 1)
Do
If character = " " Then
phrase(i) = sentence.Substring(0, place)
i += 1
End If
place += 1
character = sentence.Substring(place, 1)
Loop Until character = "."
A) Every
B) Every path
C) Every path hath
D) Every path hath a
E) Every path hath a puddle
235) Consider the following Structure definition and declaration. Which assignment statement would 235)
correctly record that player number 13 had three home runs so far this season?
Structure playerType
Dim fullname As String
Dim team As String
Dim position As String
Dim homerun As Double
Dim average As Double
Dim rbi As Double
End Structure
35
236) Suppose a structure is created with the code 236)
Structure stateUSA
Dim capCity As String
Dim stateNum As Integer
End Structure
in the Declarations section of the Code editor. Which of the following statements correctly
declares a variable of type stateWA?
A) Dim stateWA As stateUSA B) Dim stateWA As Structure
C) Dim stateWA As Member D) Dim stateUSA As stateWA
238) What is displayed in the message box by the following code? 238)
Dim message As String
Dim teamName() As String = {"Packers", "Jets", "Seahawks"}
ReDim Preserve teamName(1)
message = teamName(1)
MessageBox.Show(message)
A) Seahawks B) Jets C) Packers D) 2
240) When merging sequential files without duplications, one possible algorithm calls for opening 240)
two ordered files for input and a third file for output. Then, an item of data is retrieved from
each ordered file and the item with precedence is written out to the third file. If, however, the
two retrieved items are identical, which of the following should take place?
A) Neither item is written out to the third file and a new item is retrieved from each of the
ordered files.
B) Both items are deleted and a new item is retrieved from each of the ordered files.
C) One item is written into the third file and a new item is retrieved from each of the ordered
files.
D) Both items are written out to the third file and a new item is retrieved from each of the
ordered files.
241) Which of the following statements will result in an IndexOutOfRangeException if placed after the 241)
following line of code?
Dim arr(2) As Integer
A) arr(1) = 2 B) arr(2) = 2 C) arr(0) = 2 D) arr(3) = 2
36
242) The code for an application tests to see if a file exists using the following in the Try block: 242)
IO.File.Exists(fileName)
The first catch block is written as follows:
Catch exc As IO.IOException
The second catch block is written with the following code:
Catch
What type of exception will this second Catch block handle?
A) This block isn't designed to catch any exceptions.
B) an exception generated by deleting or renaming an open file
C) This block will catch all cases where the file specified by fileName does exist.
D) any exceptions that haven't already been handled
244) Which of the tasks is the Split function used to complete in the following code? 244)
Dim words() As String
words = line.Split(","c)
A) Split parses or separates out all items of text that are delimited by a c in the given line.
B) Split parses or separates out all items of text that are delimited by a comma in the given
line.
C) Split adds a comma delimiter between all items of text in the given line.
D) Split adds a comma followed by a c to the end of the given line.
245) The code for an application tests to see if a file exists using the following in the Try block: 245)
IO.File.Exists(fileName)
The first catch block is written as follows:
Catch exc As IO.IOException
The second catch block is written with the following code:
Catch
The Finally block of this code contains the line
sr.Close()
Which of the following statements is true in regards to the Finally block of code?
A) The Finally block of code will execute regardless of whether an exception occurred.
B) The Finally block of code will execute only if no exceptions are thrown.
C) The Finally block of code will only execute if an exception is thrown and handled.
D) The Finally block of code will never execute.
246) A radio button named radButton is placed on a form, and the statement 246)
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) False B) 1 C) True D) 2
37
In the following exercises assume the statement Dim gr As Graphics = picOutput.CreateGraphics has been
executed.
247) Give a statement that displays the value of the string variable strVar with yellow letters. 247)
A) gr.DrawString(strVar, Me.Font, Yellow, 50, 50)
B) gr.DrawString(strVar, Me.Font, Pens.Yellow, 50, 60)
C) gr.DrawString(strVar, Me.Font, Brushes.Yellow, 50, 60)
D) gr.DrawString(strVar, Me.Font, Color.Yellow, 50, 60)
248) What is the key difference between a group of check boxes attached to a group box and a group 248)
of radio buttons attached to a group box?
A) Only radio buttons can be toggled.
B) Check boxes cannot be attached to a group box.
C) The only difference is the shape of the control.
D) Only one radio button at a time can be checked.
249) The title (as seen by the user) for the group box control is set by which one of the following 249)
properties?
A) Anchor B) Name C) Tag D) Text
In the following exercises assume the statement Dim gr As Graphics = picOutput.CreateGraphics has been
executed.
250) Give a statement that draws a blue line from the upper-left corner of the picture box to the 250)
center of the picture box.
A) gr.DrawLine(Pens.Blue, picOutput.Width/2, 0, 0,
picOutput.Height/2)
B) gr.DrawLine(Pens.Blue, picOutput.Height, picOutput.Width, 0, 0)
C) gr.DrawLine(Pens.Blue, 0, 0, picOutput.Height/2,
picOutput.Width/2)
D) gr.DrawLine(Pens.Blue, 0, 0, picOutput.Width/2,
picOutput.Height/2)
251) The following form of SQL command is classified as which of the four basic types of SQL 251)
requests?
SELECT * FROM Table1 WHERE criteria
A) Request IV: make available just some of the fields of either the basic table or joined table
B) Request II: show just the records that meet certain criteria
C) Request I: show the records of a table in a specified order
D) Request III: join the tables together (connected by a foreign key) and present the records
252) Which SQL statement below would be used to display all of the records from the Cities table that 252)
contain the letter e as the second character in the name listed in their city field?
A) SELECT * FROM Cities WHERE city Like 'e%'
B) SELECT * FROM Cities WHERE city Like '_e%'
C) SELECT * FROM Cities WHERE city Like 'E%'
D) SELECT * FROM Cities WHERE city Like 'eb_%'
38
253) Which of the following is a collection of one or more (usually related) rectangular arrays of data? 253)
A) a record B) a field C) a table D) a database
255) Which of the following allows the linking together of two or more interdependent tables in a 255)
meaningful way?
A) foreign keys B) ANSI
C) duplicate entries in a single field D) null values
257) Given x = 3 and y = 1, what value will be assigned to the Double variable w when the following 257)
statement is executed?
w = (x + y) / (x — y)
A) 1 B) 2
C) 3 D) None of the above
258) What is the proper syntax when using a message dialog box? 258)
A) MessageBox.Show "Hi There", "Hi"
B) MessageBox.Show(Hi there, Hi)
C) MessageBox.Show Hi There, Hi
D) MessageBox.Show("Hi there", "Hi")
259) Assume that x, y, and temp are Integer variables. Which of the following lines of code swaps the 259)
values of x and y?
A) x = y B) temp = x C) x = y D) x = temp
y = x x = y temp = x x = y
y = temp y = temp y = temp
260) When using the logical operator "And", what part of the expression must be true? 260)
A) only the right part B) only the left part
C) both parts D) either the left or right part, but not both
261) Why is the following Select Case block invalid in Visual Basic? 261)
Select Case myName.Substring(0, 1)
Case myName < "D"
txtBox.Text = "Your name starts with A, B, or C."
End Select
A) There should not be a standard conditional statement in a value list.
B) myName.Substring(0, 1) is not valid where it is.
C) There is no selector.
D) There are not enough Case statements.
39
262) Which of the following is true? 262)
A) "Cat" > "cat"
B) "Cat" < "cat"
C) "Cat" = "cat"
D) Relational operators are only valid for numeric values.
264) Which of the following statements is guaranteed to pass the variable numVar by value to the Sub 264)
procedure Tally?
A) Tally(ByVal numVar As Double) B) Tally(numVar)
C) Tally((numVar)) D) Tally(ByVal numVar)
266) What will be the output of the following program when the button is clicked? 266)
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim number As Double = 3
DoubleAndSquare(number)
txtBox.Text = CStr(number)
End Sub
Sub DoubleAndSquare(ByRef myVar As Double)
myVar = myVar + myVar
myVar = myVar * myVar
End Sub
A) 0 B) 6 C) 3 D) 36
40
267) Assume FILE1.TXT and FILE2.TXT are sequential files containing numeric data. Based on what 267)
you think the following program segment does, what would be a good use for it?
Dim sr1 As IO.StreamReader = IO.File.OpenText("FILE1.TXT")
Dim sr2 As IO.StreamReader = IO.File.OpenText("FILE2.TXT")
Dim ans1, ans2 As String
Dim c As Integer = 0
Do While (sr1.Peek <> -1) And (sr2.Peek <> -1)
ans1 = sr1.ReadLine
ans2 = sr2.ReadLine
If ans1 <> ans2 Then
c += 1
End If
Loop
sr1.Close()
sr2.Close()
txtBox.Text = CStr(c)
A) Compare an answer key file to a student answer file to count the questions that the
student answered INCORRECTLY.
B) Count the total number of lines in the two files.
C) Count the total number of items in the two files.
D) Compare an answer key file to a student answer file to count the questions that the
student answered CORRECTLY.
268) How many times will PETE be displayed when the following lines are executed? 268)
For c As Integer = 15 to -4 Step -6
lstBox.Items.Add("PETE")
Next
A) 1 B) 2 C) 3 D) 4
269) When the number of repetitions needed for a set of instructions is known before they are 269)
executed in a program, the best repetition structure to use is a(n)
A) If block with a GoTo statement. B) Do...Loop Until structure.
C) For...Next loop. D) Do While...Loop structure.
270) Which statement is true regarding the following Dim statement? 270)
Dim state(49) As String, population(49) As Double
A) The subscripts of population() range from 0 To 49.
B) It is invalid since the two arrays must have the same data type.
C) It is invalid since more than one array is dimensioned by a single Dim statement.
D) The subscripts of state() range from 1 to 49.
272) Which of the following types of variables can only hold a single item of data? 272)
A) two-dimensional arrays B) single-subscripted variables
C) simple variables D) double-subscripted variables
41
273) Select the example statement below that would open a sequential file for output. 273)
A) Dim sr As IO.StreamReader = IO.File.AppendText("INCOME DATA.TXT")
B) Dim sw As IO.StreamWriter = IO.File.CreateText("INCOME DATA.TXT")
C) Dim sw As IO.StreamWriter = IO.File.OpenText("INCOME DATA.TXT")
D) Dim sr As IO.StreamReader = IO.File.OpenText("INCOME DATA.TXT")
274) If a sequential file is opened for input, then this allows 274)
A) data that is in the file to be used in the Visual Basic application.
B) data to be appended to the end of the file by the Visual Basic application.
C) data to be placed into the file by the Visual Basic application.
D) data to be deleted from the file.
275) Which of the following statements is true concerning the Clipboard object? 275)
A) It is used to create a sequential data file that permanently maintains copied items on the
hard drive.
B) It is a portion of memory that holds information and has no properties or events.
C) It is an object that appears on the form and is triggered by its Click event.
D) It is used to produce the Microsoft "Help Assistant" that takes the shape of a paper clip.
276) Which of the following is not a main type of event that can be triggered by user selections of 276)
items in a list box?
A) FillDown event B) Click event
C) SelectedIndexChanged event D) DoubleClick event
279) What will be the value of numVar when the following code is executed? 279)
Dim strVar As String, numVar As Integer
strVar = "Now is the time for all good men"
numVar = strVar.IndexOf("the time for")
A) 7 B) 8
C) "12" D) "Now is all good men"
42
280) What will be the output of the following statement? 280)
txtBox.Text = FormatPercent(2/3, 4)
A) 66.66% B) 66.6667% C) 0.6666 D) 0.6667
282) Suppose a variable is passed by reference to a parameter of a Sub procedure, and the parameter 282)
has its value changed inside the Sub procedure. What will the value of the variable be after the
Sub procedure has executed?
A) It will retain the value it had before the call to the Sub procedure.
B) Its value can't be determined without more information.
C) It will have the newly modified value from inside the Sub procedure.
D) None of the above
283) What does the following program do with a person's name? 283)
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim name, test As String
Dim n As String = ""
name = InputBox("Enter your first name:")
For i As Integer = 0 To name.Length - 1 Step 2
test = name.Substring(i, 1)
n = test & n
Next
txtBox.Text = n
End Sub
It displays the name
A) in reverse order and skips every other letter.
B) as it was entered.
C) as it was entered, but skips every other letter.
D) in reverse order.
43
284) Given the following array, what value will be assigned to num? 284)
A) 0
B) 24
C) 4
D) 19
E) None of the above
285) What is displayed in the text box by the following two lines of code? 285)
Dim language() As String = {"V", "B", " ", "2", "0", "0", "5"}
txtBox.Text = Join(language, "")
A) "V","B"," ","2","0","0","5" B) "V","B","","2","0","0","5"
C) V,B, ,2,0. 0. 5 D) VB 2005
286) A check box control named chkFirst contains the following code in its CheckedChanged event 286)
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 not appear using this source code.
B) The message "hello" will appear when the user checks the control and again when it is
unchecked.
C) The message "hello" will appear when the user checks the control but not when it is
unchecked.
D) The message "hello" will appear when the user unchecks the control but not when it is
checked.
44
289) What will be displayed when the button is clicked? 289)
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim x, y As String
x = "tin"
y = "can"
Swap(x, y)
txtOutput.Text = x & " " & y
End Sub
Sub Swap(ByRef x As String, ByVal y As String)
Dim temp As String
temp = x
x = y
y = temp
End Sub
A) tin can B) can can C) can tin D) tin tin
290) What will be displayed by the following program when the button is clicked? 290)
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim x, y As String
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
x = sr.ReadLine
For k As Integer = 1 To 4
y = sr.ReadLine
If x > y Then
x = y
End If
Next
sr.Close()
txtBox.Text = x
End Sub
Assume the five lines of the file DATA.TXT contain the following entries: CAROL, DAVE, ABE,
EMILY, BOB.
A) ABE B) BOB C) EMILY D) CAROL E) DAVE
B) num()
457 457 457 458
C) years()
1877 1944 2011 4301
D) nbrhoods()
Hockinson Bush Prairie Dollars Corner Battle Ground
45
292) Which of the tasks is the Join function used to complete in the following statement? 292)
Dim line As String
line = Join(strArrData, ",")
A) Join parses or separates out all items of text that are delimited by a comma in line.
B) Join parses or separates out all items of text that are delimited by a comma in strArrData.
C) Join concatenates the values of all elements of line, and adds a comma to the end of the
line.
D) Join concatenates the values of all elements of the array strArrData, and adds a comma
delimiter between successive values.
293) A program contains two forms with the names Form1 and Form2. Form1 contains a button 293)
called btnDisplay, and the following code is placed inside btnDisplay's Click event procedure.
Dim secondForm As New Form2()
secondForm.ShowDialog()
MessageBox.Show("Hello")
Which of the following statements is true after the user clicks on btnDisplay at run time?
A) Form2 appears in front of Form1 and the user will only be able to set the focus to Form2.
B) A message box displaying the text "Hello" appears in front of Form2 and Form1.
C) Form2 appears behind Form1 and the user will be able to set the focus to either form.
D) A message box displaying the text "Hello" appears behind Form2 and Form1.
294) Which property should be used to bind a list box to a data table? 294)
A) The DataSource property of the list box.
B) The Items property of the list box.
C) The DataSource property of the data table.
D) The Bound property of the list box.
295) What is the correct statement when declaring and assigning the value of 100 to an Integer 295)
variable called numPeople?
A) Dim numPeople = 100
B) Dim numPeople = Int(100)
C) Dim numPeople As Integer = 100
D) numPeople = 100
296) What happens to a variable declared locally inside a Sub procedure after the procedure 296)
terminates?
A) It maintains its value even after the End Sub statement executes.
B) It loses its value temporarily after the End Sub statement executes, but regains that value
upon re-entry to the Sub procedure.
C) It ceases to exist after the End Sub statement executes.
D) It is reset to its default value.
46
297) What will be displayed by the following program when the button is clicked? 297)
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim x, y, z As Double
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
y = 0
x = CDbl(sr.ReadLine)
Do While x < 5
If x = 4 Then
sr.Close()
sr = IO.File.OpenText("DATA.TXT")
End If
z = x + y
x = CDbl(sr.ReadLine)
y = CDbl(sr.ReadLine)
Loop
txtBox.Text = CStr(z)
sr.Close()
End Sub
The nine lines of the file DATA.TXT contain the following data: 3, 4, 6, 8, 1, 2, 5, 9, 3.
A) 9
B) 10
C) 14
D) 7
E) None of the above
298) When using the bubble sort algorithm, how many passes will be required to correctly sort a list 298)
containing the names Pebbles, Barney, Wilma, Fred, and Dino?
A) 2 B) 5 C) 4 D) 3
299) Which of the following statements is used when you want to add data to the end of an existing 299)
sequential file?
A) Dim sr As IO.StreamReader = IO.File.AddText("DATA.TXT")
B) Dim sw As IO.StreamReader = IO.File.AppendText("DATA.TXT")
C) Dim sw As IO.StreamWriter = IO.File.CreateText("DATA.TXT")
D) Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
300) A form contains a button called btnDisplay, and the following code is placed inside btnDisplay's 300)
Click event procedure. At run time, which one of the following cannot possibly be displayed in
the message box when the user clicks on btnDisplay?
Dim rndNum As New Random()
Dim num1 As Integer
num1 = rndNum.Next(0, 3)
MessageBox.Show(CStr(num1))
A) 3 B) 2 C) 1 D) 0
47
Answer Key
Testname: FINALPREP
1) A
2) B
3) A
4) A
5) A
6) B
7) E
8) D
9) C
10) B
11) C
12) D
13) B
14) E
15) E
16) B
17) B
18) C
19) B
20) B
21) C
22) E
23) C
24) D
25) D
26) D
27) B
28) D
29) D
30) B
31) C
32) D
33) A
34) B
35) B
36) D
37) B
38) D
39) B
40) D
41) A
42) D
43) B
44) A
45) C
46) B
47) D
48) D
49) A
48
Answer Key
Testname: FINALPREP
50) A
51) D
52) B
53) C
54) A
55) C
56) A
57) B
58) C
59) B
60) A
61) C
62) C
63) D
64) A
65) D
66) A
67) D
68) D
69) B
70) C
71) A
72) D
73) C
74) C
75) C
76) D
77) A
78) D
79) C
80) B
81) A
82) B
83) D
84) B
85) A
86) C
87) D
88) D
89) C
90) D
91) D
92) B
93) D
94) D
95) D
96) D
97) D
98) B
49
Answer Key
Testname: FINALPREP
99) A
100) C
101) C
102) D
103) D
104) A
105) C
106) D
107) A
108) D
109) E
110) C
111) C
112) C
113) D
114) C
115) B
116) B
117) D
118) A
119) C
120) A
121) D
122) D
123) B
124) A
125) D
126) C
127) B
128) B
129) A
130) C
131) D
132) A
133) B
134) A
135) C
136) C
137) A
138) A
139) C
140) C
141) B
142) A
143) B
144) C
145) A
146) D
147) A
50
Answer Key
Testname: FINALPREP
148) A
149) C
150) C
151) B
152) A
153) B
154) C
155) D
156) D
157) A
158) B
159) A
160) A
161) A
162) B
163) B
164) D
165) D
166) B
167) B
168) D
169) A
170) C
171) B
172) B
173) C
174) C
175) A
176) A
177) B
178) C
179) A
180) C
181) D
182) D
183) B
184) C
185) A
186) C
187) C
188) B
189) B
190) A
191) D
192) D
193) D
194) B
195) C
196) B
51
Answer Key
Testname: FINALPREP
197) D
198) B
199) B
200) B
201) D
202) A
203) B
204) B
205) B
206) A
207) B
208) D
209) C
210) A
211) C
212) C
213) D
214) A
215) A
216) D
217) A
218) C
219) D
220) B
221) B
222) B
223) D
224) B
225) B
226) B
227) D
228) B
229) B
230) D
231) B
232) C
233) B
234) B
235) A
236) A
237) D
238) B
239) A
240) C
241) D
242) D
243) A
244) B
245) A
52
Answer Key
Testname: FINALPREP
246) C
247) C
248) D
249) D
250) D
251) B
252) B
253) D
254) C
255) A
256) C
257) B
258) D
259) B
260) C
261) A
262) B
263) B
264) C
265) D
266) D
267) A
268) D
269) C
270) A
271) B
272) C
273) B
274) A
275) B
276) A
277) A
278) C
279) A
280) B
281) A
282) C
283) A
284) D
285) D
286) B
287) B
288) D
289) B
290) A
291) D
292) D
293) A
294) A
53
Answer Key
Testname: FINALPREP
295) C
296) C
297) D
298) D
299) B
300) A
54