Vous êtes sur la page 1sur 9

Visual Basic 2005 Sample Midterm Questions

TRUE-FALSE
If the statement is always true, mark true on the ScanTron sheet, otherwise mark false.
1. The properties of an object can only be set in the Properties window.
2. A MenuItem object does not have a click event procedure.
3. The only purpose of a GroupBox object is to display a title for a set of RadioButton objects.
4. Integer division is performed with the \ operator to return only the whole portion of the quotient.
5. A prompt is a label placed near a textbox describing the expected input from the user.
6. The keystroke way to cut text is Ctrl X.
7. The keystroke way to copy text is Ctrl C.
8. The keystroke way to paste text is Ctrl P.
9. After the properties of an object are set they may not be changed.
10. Context sensitive help is available by pressing the F1 key.
11. Program execution can be started by the F6 key.
12. The text property and the name property of a textbox are the same property.
13. When naming a textbox you should use the prefix txt.
14. Names of labels should be prefixed with lab.
15. The name of a button should be prefixed with btn.
16. The ASCII code of A is 65.
17. Variables in Visual Basic can be used only for numeric values.
18. When an object is selected, it is said to have the focus.
19. You use an If-Then statement to choose between alternative possibilities.
20. Indenting code as you program makes your code easier to read.
21. When comments are included in code and the default colors are active, Visual Basic turns comments to
green.
22. When used in the text property of a button, the ampersand underlines the character it precedes.
23. The triangle inequality states the sum of the lengths of any two sides of a triangle must be equal to the
third side.
24. A Dim statement reserves memory for variables.
25. A variable declared in one event procedure is available in all the event procedures of that form.

26. The IsNumeric function returns True if its argument can legally be converted to a number; otherwise, it
returns False.
27. The Randomize statement uses the value returned by the system timer as the new seed value for the Rnd
function.
28. About boxes usually have a sizable border style rather than fixed.
29. In the variable assignment statement intX= 14 Mod 4, intX is assigned the value 2.
30. An algorithm is a set of steps that tell how to solve a problem.
31. A Boolean expression is an expression that evaluates to true or false.
32. The values of static variables are always retained in memory for the duration of a programs execution.
33. Concatenation is the process of joining two or more strings into one string.
34. The Unicode value for an uppercase letter is the same for the corresponding lowercase letter.
35. ChrW( ) is a built-in function that returns the character corresponding to an integer representing a
Unicode value.
36. The statement intN = intN + 1, uses intN as a counter variable.
37. intN = intN + 1 is the same as intN += 1
38. An argument is a variable or value passed to a procedure.
39. ByVal is a keyword used to declare a value parameter in a procedure.
40. ByRef is a keyword used to declare a reference parameter in a procedure.
41. A value parameter is a variable declared in a procedure to accept a copy of an argument. Value
parameters cannot alter the value of the actual argument used in the procedure call.
42. A ByRef parameter uses the same memory location as the argument it is passed.
43. A Call statement is used to invoke a sub procedure.
44. A Return statement can be used in a user-defined function to send a value back to the expression which
called the function.
45. A Sub procedure must always be declared with parameters.
46. Selecting from an AutoList reduces the chance of typing errors in code.
47. In the Code window, a blue wavy underline indicates a syntax error.
48. A static variables scope is local to the procedure in which it is declared, but its lifetime is the duration of
the program
49. A static variable is declared with the keyword Dim
50. An infinite loop continues forever

PART II - MULTIPLE CHOICE


Choose the best answer from the choices and mark your choice on the ScanTron answer sheet.
Scratch work may be done on this exam booklet.
51. To count how many times a section of code has been executed, use the statement
a) intT = intT + intX
b) intC = intC + 1
c) intT + intX = intT
d) intC + 1 = intC
52. To step through a loop from a larger limit to a lower one, make the step
a) increment positive
b) increment negative
c) lower limit negative
d) upper limit negative
53. Which property sets the maximum number of characters that can be entered in a textbox.
a) MaxLength
b) MaxValue
c) MinValue
d) MultiLine
54. What of the following are the commonly used Logical Operators?
a) But, And
b) Not, And, Or
c) Yet, But
d) Neither, Nor
55. What is the Unicode value of the letter Z?
a) 65
b) 90
c) 91
d) 255
56. Which property controls the text appearing in the forms title bar?
a) Caption
b) Name
c) Text
d) Title
57. Which control is best for displaying text that you dont want the user to change.
a) Menu Item
3

b) Button
c) Label
d) TextBox
58. The largest value that can be stored by an integer type variable is
a) 255
b) 256
c) 32767
d) 2147483647
59. The size of a font is measured in
a) Characters
b) Inches
c) Points
d) Twips
60. Actions such as click, doubleclick, keypress, and scroll are called
a) Episodes
b) Events
c) Happenings
d) Procedures
61. Which control do you use to accept or display information you will allow the user to change?
a) Button
b) Form
c) Label
d) Text box
62. Which of the following is a valid statement
a) txtName.Text (Jones)
b) txtName.Caption = Jones
c) txtName.Text = &Jones&
d) txtName.Text = Jones
63. Which is the best data type to use for a variable that will always contain whole numbers in the range 0 to
20,000.
a) Boolean
b) Integer
c) Long
d) Single
64. Processing the same sequence of steps repeatedly is referred to as
a) looping
4

b) parallel processing
c) resequencing
d) branching
65. The Rnd function
a) rounds off numbers
b) generates a random number between 0 and 1
c) generated a random number between 1 and 10
d) generates a random number between -1 and 1
66. Given this program:
intX = 1
Do While intX <> 4
lstDisplay.Items.Add (intX)
IntX = intX + 1
Loop
a) the program will display 1, 2, 3
b) the program will display 1, 2, 3, 4
c) the program will display 1, 2, 3, 4, 5
d) the program will display 1, 2
67. Assuming that A, B, C, D, E, and F have been properly initialized, the following program
fragment is incorrect because
For K = A To B Step C
For L = D To E Step F
lblDisplay.Text = L + K
Next K
Next L
a)
b)
c)
d)

a variable name cannot be used as the initial value and the final value in a FOR statement
nested FOR and NEXT statements are not allowed
two FOR statements cannot appear one after the other in a program
the inner FOR-NEXT loop must be entirely contained within the outer FOR-NEXT loop

68. The process of eliminating errors from a computer program is called:


a) initializing
b) compiling
c) debugging
d) documenting
6971. Spacing, indentation, and documentation within a program
a) are important because they make a
5

program easier to understand


b) are needed only if anyone other than a
technical person will be reviewing it
c) are required for proper execution of the
program
d) are not important
70. To display an "About" form in Visual Basic, we can use
a) frmAbout.ShowDialogue
b) frmAbout.Display
c) frmAbout.Get
d) frmAbout.Reveal
71. To simulate rolling a die, we can use:
a) Int (6 * Rnd + 1)
b) Int (6 * Rnd)
c) Int (6 * Rnd * 1)
d) Rnd (6 * N + 1)
72. Suppose intA=5, intB=5, and intC=6 then
If Not(intA=intB And intC<5) Then
lblDisplay.text = True
Else
lblDisplay.text = False
End If
will display:
a)
b)
c)
d)

True
False
True False
nothing

73. In this If-Then statement


If condition Then
statements
End If
statements
If the condition tested is false, the program
a) executes the statements between Then and the End If
6

b) executes the statements following the End If


c) does not execute any statements at all
d) executes both the statements between the Then and the End If and the statements following the End
If

PART III WHAT IS DISPLAYED?


In the space provided on this paper, print the exact output from each of the following lines.
1. lblDisplay.Text = 10 + 3 * 6

answer ____________________

2. lblDisplay.Text = 2 ^ 3 + 5 * 4

answer ____________________

3. lblDisplay.Text = 2 + 9 ^ (1 / 2)

answer ____________________

4. lblDisplay.Text = 6+3-2

answer ____________________

5. lblDisplay.Text = 2 + 9 ^ 1 / 2

answer ____________________

REWRITE EACH LINE


Each of the following 3 lines contains a syntax error, logical error, or run-time error. Rewrite the
line so that it is error free.
Dim intNum =0

intNum = Value(Me.txtNum.Text)

lblDisplay = strMessage

WHAT IS DISPLAYED?
Neatly print in the space provided the output from each line. There are no errors.
Dim strCountry As String = "UniTED StateS"
Dim strFirst As String = "Golden"
Dim strLast As String = "
Griffins" ' there are 5 spaces in front of Griffins
1.

lstDisplay.Items.Add(strCountry.Length)

ans _______________

2.

lstDisplay.Items.Add(strCountry.ToUpper)

ans _______________

3.

lstDisplay.Items.Add(strCountry.Chars(1))

ans _______________

4.

lstDisplay.Items.Add(strCountry.Chars(5))

ans _______________

5.

lstDisplay.Items.Add(strCountry.Substring(0, 1))

ans _______________

WHAT IS DISPLAYED?
Study the code. Determine the values of a, b, and c. Write the answers in the spaces provided.
Private Sub btnSubOne_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSubOne.Click
Dim a As Integer, b As Integer, c As Integer
a = 3
b = 9

(a) _________

Call One(a, b, c)
lstDisplay.Items.Add(a)

(b) _________
lstDisplay.Items.Add(b)

(c) _________

lstDisplay.Items.Add(c)
End Sub
Private
Dim
x =
c =
End Sub

Sub One(ByVal a As Integer, ByVal b As Integer, ByRef c As Integer)


x As Integer
a + b
x + a

End Sub

WRITE THE CODE


1. Write the button click event code that will display in a list
box named lstDisplay the multiplication tables from 1 1
= 1 to 25 25 = 625. The code should put a blank line
between each table as illustrated in the diagram. This
question is asking for the nested loop code for the
assignment which we completed in class.

Vous aimerez peut-être aussi