Visual Basic MCQ

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?

a) Procedural
b) Object-oriented
c) Functional
d) Logic-based

Answer:

b) Object-oriented

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?

a) Byte
b) Float
c) String
d) Double

Answer:

b) Float

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?

a) var x as Integer
b) Integer x = 5
c) Dim x As Integer
d) x: Integer = 5

Answer:

c) Dim x As Integer

Explanation:

In VB, variables are declared using the Dim statement.

4. Which control allows for multi-line input in VB?

a) TextBox
b) Label
c) MultiLineBox
d) RichTextBox

Answer:

a) TextBox

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?

a) Catch
b) Handle
c) Error
d) Except

Answer:

a) Catch

Explanation:

In VB, exceptions are caught using the Try…Catch construct.

6. The default property for a TextBox is:

a) MultiLine
b) Text
c) ReadOnly
d) Size

Answer:

b) Text

Explanation:

The default property for a TextBox control in VB is "Text".

7. Which event gets triggered when a form loads in VB?

a) OnLoad
b) Load
c) FormStart
d) Begin

Answer:

b) Load

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?

a) For..Next
b) While..End While
c) Do..Loop
d) Loop..Until

Answer:

d) Loop..Until

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?

a) EndSub
b) Terminate
c) Finish
d) End

Answer:

d) End

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?

a) The current object
b) The main function
c) The parent object
d) The base class

Answer:

a) The current object

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?

a) Length()
b) StrLength()
c) Len()
d) Size()

Answer:

c) Len()

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)?

a) 1
b) 2.5
c) 2
d) 0

Answer:

a) 1

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?

a) Static
b) Const
c) ReadOnly
d) Fixed

Answer:

b) Const

Explanation:

In VB, constants are defined using the Const keyword.

14. Which of the following is NOT an access modifier in VB?

a) Public
b) Private
c) Protected
d) Closed

Answer:

d) Closed

Explanation:

"Closed" is not a valid access modifier in Visual Basic.

15. What does the ByVal keyword mean in a VB function parameter?

a) Pass by reference
b) Pass by value
c) Pass by memory address
d) Pass by pointer

Answer:

b) Pass by value

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?

a) Global
b) Public
c) Local
d) Shared

Answer:

c) Local

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?

a) CInt()
b) StrToInt()
c) Convert.ToInt32()
d) Both a and c

Answer:

d) Both a and c

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?

a) // … //
b) <!– … –>
c) /* … */
d) ' … '

Answer:

d) ' … '

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?

a) Dim obj As New MyClass()
b) Create obj As MyClass
c) New obj Of MyClass
d) Instantiate obj As MyClass

Answer:

a) Dim obj As New MyClass()

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?

a) OnClose
b) CloseEvent
c) FormClosed
d) Destroy

Answer:

c) FormClosed

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?

a) Public
b) Private
c) Protected
d) Shared

Answer:

b) Private

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?

a) Exit
b) Break
c) Stop
d) Terminate

Answer:

a) Exit

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?

a) ArrayList
b) List
c) HashSet
d) Collection

Answer:

c) HashSet

Explanation:

In VB, the HashSet collection does not allow duplicate elements.

24. Which of the following is NOT a type of error in VB?

a) Compile-time
b) Logical
c) Run-time
d) Syntax-time

Answer:

d) Syntax-time

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?

a) Raise
b) Alert
c) Throw
d) Error

Answer:

c) Throw

Explanation:

In VB, the Throw keyword is used to raise exceptions.


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top