Exam: VB.
NET Comprehensive Test
Part 1: Multiple Choice (5 Questions)
1. What does the following loop do?
For i = 1 To 5
Console.WriteLine(i * 2)
Next i
a) Prints numbers from 1 to 5
b) Prints numbers from 2 to 10, doubling each iteration
c) Prints odd numbers from 1 to 5
d) Causes an error
2. What property of a TextBox control is used to set or get its text?
a) Value
b) Name
c) Text
d) Content
3. What does Len("Visual Basic") return?
a) 11
b) 10
c) 12
d) 9
4. What will the following array initialization do?
Dim arr(3) As Integer
arr(0) = 1
arr(1) = 2
arr(2) = 3
arr(3) = 4
a) Create an array with 3 elements
b) Throw an error because arrays are 0-indexed
c) Create an array with 4 elements
d) None of the above
5. What event is triggered when a button is clicked in VB.NET?
a) MouseDown
b) TextChanged
c) Click
d) KeyDown
Part 2: Trace the Code (3 Questions)
6. What is the output of the following code?
Dim result As String = ""
For i = 1 To 3
For j = 1 To i
result &= "*"
Next j
result &= vbCrLf
Next i
Console.WriteLine(result)
7. Analyze the following code and state the final values of sum and product:
Dim sum As Integer = 0
Dim product As Integer = 1
For i = 1 To 4
sum += i
product *= i
Next i
8. Predict the output of this program:
Dim myString As String = "Visual Basic"
Console.WriteLine(myString.Substring(0, 6))
Console.WriteLine(myString.IndexOf("B"))
Part 3: Write Code (4 Questions)
9. Write a program that does the following:
Accepts a sentence from the user.
Counts the number of words in the sentence.
Displays the result.
10. Write a function that takes an integer array as input and returns the largest number in the array.
11. Create a VB.NET program using a ListBox control that displays all even numbers from 1 to 20 when a button
is clicked.
12. Write a loop to reverse the characters of a string entered by the user.
Part 4: Advanced Challenge (1 Question)
13. Develop a program for a basic calculator with a graphical interface:
Add two TextBox controls for number input.
Add buttons for addition, subtraction, multiplication, and division.
Display the result in a Label.