Visual Basic (VB) is an event-driven programming language from Microsoft that provides a graphical user interface to the programming model. Test your foundational knowledge of Visual Basic with these 25 multiple-choice questions.
1. What type of programming language is Visual Basic?
Answer:
Explanation:
While Visual Basic does support procedural programming, it is fundamentally an object-oriented language.
2. Which of the following is NOT a valid data type in VB?
Answer:
Explanation:
Visual Basic does not have a data type named "Float". It uses "Single" for floating-point numbers.
3. Which of the following is the correct way to declare a variable in VB?
Answer:
Explanation:
In VB, variables are declared using the Dim statement.
4. Which control allows for multi-line input in VB?
Answer:
Explanation:
The TextBox control with the MultiLine property set to true allows for multi-line input.
5. Which keyword is used to handle exceptions in VB?
Answer:
Explanation:
In VB, exceptions are caught using the Try…Catch construct.
6. The default property for a TextBox is:
Answer:
Explanation:
The default property for a TextBox control in VB is "Text".
7. Which event gets triggered when a form loads in VB?
Answer:
Explanation:
The "Load" event gets triggered when a form loads in Visual Basic.
8. Which of the following is NOT a valid loop in VB?
Answer:
Explanation:
There isn't a "Loop..Until" loop in VB. The correct syntax is "Do..Until".
9. In VB, which keyword is used to end a procedure?
Answer:
Explanation:
In VB, the "End" keyword is used to end a procedure or a block of code.
10. What does the Me keyword refer to in VB?
Answer:
Explanation:
In VB, the Me keyword refers to the current instance of the object where it is used.
11. Which function returns the length of a string in VB?
Answer:
Explanation:
The Len() function returns the length of a string in VB.
12. What is the result of the following code: MsgBox(5 Mod 2)?
Answer:
Explanation:
The Mod operator returns the remainder of a division. So, 5 divided by 2 gives a remainder of 1.
13. Which keyword is used to define a constant in VB?
Answer:
Explanation:
In VB, constants are defined using the Const keyword.
14. Which of the following is NOT an access modifier in VB?
Answer:
Explanation:
"Closed" is not a valid access modifier in Visual Basic.
15. What does the ByVal keyword mean in a VB function parameter?
Answer:
Explanation:
In VB, ByVal means that the parameter is passed by value.
16. What type of variable is accessible only within the procedure where it's declared?
Answer:
Explanation:
Local variables are accessible only within the procedure or function where they are declared.
17. Which of the following methods can be used to convert a string to an integer in VB?
Answer:
Explanation:
In VB, you can use CInt() or Convert.ToInt32() to convert a string to an integer.
18. How would you comment out multiple lines of code in VB?
Answer:
Explanation:
In VB, a single quote ' is used to comment out a line. For multiple lines, you would have to use a single quote at the beginning of each line.
19. Which of the following is a method to create a new instance of an object in VB?
Answer:
Explanation:
The correct syntax to create a new instance of an object in VB is Dim obj As New MyClass().
20. Which of the following event is fired when a form is closed?
Answer:
Explanation:
The "FormClosed" event is triggered when a form is closed in VB.
21. What is the default access level for class members if no access modifier is specified?
Answer:
Explanation:
If no access modifier is specified for a class member in VB, it defaults to "Private".
22. Which keyword stops the execution of a loop, regardless of the loop condition?
Answer:
Explanation:
In VB, the Exit keyword is used within a loop to stop its execution immediately, regardless of the loop's condition.
23. Which of the following collections does NOT allow duplicate elements?
Answer:
Explanation:
In VB, the HashSet collection does not allow duplicate elements.
24. Which of the following is NOT a type of error in VB?
Answer:
Explanation:
"Syntax-time" is not a recognized type of error in VB. The common types of errors include compile-time, logical, and run-time errors.
25. Which keyword is used to raise exceptions in VB?
Answer:
Explanation:
In VB, the Throw keyword is used to raise exceptions.