Visual Basic MCQ (Multiple Choice Questions)

Here are 1000 MCQs on Visual Basic (Chapterwise).

1. Who developed Visual Basic?
a) Symantec
b) Ashton-Tate
c) Microsoft
d) Sybase
View Answer

Answer: c
Explanation: Visual Basic is a programming language and environment developed by Microsoft. Visual Basic first version was published in 1991.

2. Which of the following statement is used to define a class in visual basic?
a) Event class statement
b) Class statement
c) Form class statement
d) Event statement
View Answer

Answer: b
Explanation: The class statement is used to define a class in visual basic. The class statement begins with public class classname clause and ends with End class clause. Within the class statement, you write the code to tell the form and the object how to react to the user’s action.

3. Which of the following extension is used to represent the project file in Visual Basic?
a) .vbp
b) .vb
c) .cls
d) .vvb
View Answer

Answer: a
Explanation: The .vbp file extension is used to represent the program file in Visual Basic. .cls is used to save the Class module.

4. If you keep a variable undeclared, it is automatically taken as to which of the following data type in Visual Basic?
a) Char
b) Int
c) Object
d) String
View Answer

Answer: c
Explanation: Visual basic can create variables “on the fly”. This means that if your code contains undeclared variables, Visual basic creates the variable for you and assigns object data type to it. An undeclared variable is a variable, which does not appear in the declaration statement i.e. the Dim statement.

5. Which of the following applications can be developed using Visual Basic tool?
a) Graphical User Interface
b) Real-time
c) Character User Interface
d) All of the mentioned
View Answer

Answer: a
Explanation: Visual Basic tool provides an easy way to develop graphical user interface (GUI) applications.
advertisement
advertisement

6. In Visual Basic, which of the following is used for coding single-alternative and dual-alternative selection structures?
a) Switch-Case block
b) If…Then…Else statement
c) function overloading
d) Recursion
View Answer

Answer: b
Explanation: In Visual Basic If…Then…Else statement is used for coding single-alternative and dual-alternative selection structures. The If…Then…Else statement statements provide for a statement block where the condition may be true and another if the condition is false.

7. What will be the output of the following Visual Basic code, If the intnumber variable is 110?

If intnumber<=100 Then
   Intnumber=intnumber*2;
Else
   Intnumber=intnumber*3;
EndIf

a) 180
b) 330
c) 156
d) 270
View Answer

Answer: b
Explanation: Since the intnumber is 110, i.e. it is greater than 100, thus else part of the code will be executed, i.e., the if part of the code will not be executed. Thus intnumber=intnumber*3 will be executed, thus 110*3=330 will be stored in intnumber.

8. In the Visual Basic application, which of the following are listed in a properties window?
a) Items
b) Values
c) Attributes
d) Objects
View Answer

Answer: c
Explanation: Attributes also known as properties are listed in a Properties Window. Attributes are keyword-like tags in which you can specify additional information about entities defined in Visual Basic application. Attributes are saved as assembly’s metadata.

9. What will be the output of the following Visual Basic expression?

Financial.Pmt (0.05, 3, 9000)

a) -3043.88
b) -3034.88
c) -3408.48
d) -3304.88
View Answer

Answer: d
Explanation: The above expression calculates for a loan of Rs. 9000 for 3 years at 5% interest. Rate is 0.05, Nper is 3 and PV is 9000. The annual payment rounded off to nearest is, -3304.88.

10. Which of the following is commonly used to perform an immediate action when clicked in Visual Studio?
a) Button control
b) Close
c) End
d) Exit
View Answer

Answer: a
Explanation: Every application should give the user a way to exit the program. Most Windows Application accomplishes this task using the Exit option. In visual basic a button is used for sending an application. It is commonly used to perform immediate action when clicked.
advertisement

11. In the following Visual Basic code, what will be in msg, if str contains “visual basic”?

Dim str as String
Dim  msg as String
If str.toUpper=”VISUAL BASIC” 
   msg=”VB.Net”
Else
   msg=”Not Visual Basic”
EndIf

a) Bye
b) Hi
c) Logical Error
d) Compiler Error
View Answer

Answer: b
Explanation: str contains “visual basic”. When we do str.toUpper, the string in str is changed to “VISUAL BASIC”. Thus, the comparison satisfies, and the if statement is executed, since the comparison returns a true value. Thus msg will contain “VB.Net”.

12. Which of the following displays the list of projects contained in the Visual Basic current solution?
a) List Window
b) Project Window
c) Catalogue Window
d) Solution Explorer Window
View Answer

Answer: d
Explanation: The Solution Explorer Window provides you with an organized view of your projects and their files as well as ready access to the commands that pertain to them. A toolbar associated with this window offers commonly used commands for the item you highlight in this list.

13. Which of the following method is used to sort an array in visual basic?
a) Array.Sort()
b) Array.sortAscending()
c) Array.arrayArrange()
d) Array.arrange()
View Answer

Answer: a
Explanation: You can use the Array.Sort method to sort a one-dimensional array’s values in ascending order. To sort the values in descending order, you first use the Array.Sort method to sort the values in ascending order, and then use the Array.Reverse method to reverse the values. The syntax is as follows, where the arrayName is the name of the array:
Array.Sort(arrayName)
advertisement

14. Which of the following is the caption part for the following Visual Basic command?

MessageBox.Show("Delete Visual Basic?","VB.Net",MessageBoxButtons.YesNo,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2).

a) MessageBoxButtons.YesNo
b) MessageBoxIcon.Exclamation
c) “VB.Net”
d) “Delete Visual Basic?”
View Answer

Answer: c
Explanation: The syntax of the MessageBox.Show is-

MessageBox.Show (text, caption, buttons, icon, [defaultButton])

The caption is given as the second component in the syntax. In the above statement, the second component is the “VB.Net”, thus it is the caption.

15. Which of the following instruction tells the computer to close the current form in Visual Basic?
a) This.Close()
b) Me.Close()
c) Close.this()
d) Close()
View Answer

Answer: b
Explanation: The Me.Close() instruction tells the computer to close the current form. If the current form is the only form, then this instruction closes the application. In the instruction Me is a keyword that refers to the current form and Close is one of the methods available in visual basic. A method is a predefined procedure that you can invoke when needed.

16. Object respond to an event by writing __________
a) Defining events
b) Operations
c) Defining actions
d) Event procedures
View Answer

Answer: d
Explanation: You tell an object how to respond to an event, by writing event procedures, which is a set of visual basic instructions that are processed only when the event occurs.

17. What output will be returned if the following Visual Basic code is executed?

strVisualBasic = "Sanfoundry, VB.Net"
intCharIndex = strVisualBasic.IndexOf("VB")

a) 11
b) 12
c) False
d) True
View Answer

Answer: b
Explanation: The IndexOf method returns the index of the first character of the sequence, thus it returns 11 as the index of the first character “V” is 11. If it would have been Contains Method, it would have returned True.

18. What will be the output of the following Visual Basic code?

Dim intScores As Integer = {78, 83, 75, 90}
Array.Reverse(intScores)

a) 78,75,83,90
b) 90,75,83,78
c) 78, 83, 75,90
d) 75,78, 83,90
View Answer

Answer: b
Explanation: Array.Reverse method reverses the array list. It reverses the contents of the array, placing the values in the following order: 90, 75, 83, and 78.

19. Which of the following is used to write a stream of characters in Visual Basic?
a) StreamReader object
b) StreamReader class
c) StreamWriter object
d) StreamWriter class
View Answer

Answer: c
Explanation: Programmers refer to a sequence of characters as a stream of characters. In Visual Basic, you use a StreamWriter object to write a stream of characters to a sequential access file. Before you create the StreamWriter object, you first declare a variable to store the object in the computer’s internal memory. The syntax is as follows:

{Dim | Private} streamWriterVariableName As IO.StreamWriter

The IO in the syntax stands for Input/Output.

20. What is the value of len in the following Visual Basic code?

Dim strVB() As String = {"Sanfoundry", "Visual Basic", "VB.Net", "Visual Studio"}
Dim len As Integer
len = strVB.Length()

a) 3
b) 5
c) 4
d) 0
View Answer

Answer: c
Explanation: Array index starts from 0. So the index of the first element is 0, the second is 1, and so on. But the length is a total number of elements in the array, which is 4.

21. Which of the following is the default name assigned to the label control in Visual Basic?
a) Label1
b) DefaultLabel
c) Label0
d) NewLabel
View Answer

Answer: a
Explanation: Label1 is the default name applied to the label control. When a first label is on the form it is named as Label1. When another label is brought in, it is named as Label2 and it goes so on.

22. Which of the following toolbox is used to include an image on the Visual Basic form?
a) Add Image box
b) Picture Box
c) Add Picture Box
d) Image box
View Answer

Answer: b
Explanation: We can include an image in the form using Picture box control, which is instantiated using picture box tool. As we include the picture box, the properties of it appears in the Properties Window.

23. In visual basic language what are the rules of a programming language called?
a) Grammar
b) Order
c) Syntax
d) Rules
View Answer

Answer: c
Explanation: The Code editor provides the code template to help you follow the rules of the visual basic language. The rules of a programming language are called its syntax. The first line in the code template is called the procedure header and the last line the procedure footer.

24. What happens when both the minimize box and maximize box property are set to false in Visual Basic?
a) Both are removed from the title bar
b) Both are disabled
c) This situation shows an exception
d) This situation shows an error
View Answer

Answer: a
Explanation: When both the minimize box property and maximize box property are set to false, the buttons are not disabled that is they are not grayed out, instead they are removed from the title bar.

25. In Visual Basic, which of the following keyword tells the computer to pass the variable’s address rather than its contents?
a) ByAdd
b) ByPoint
c) ByRef
d) ByVal
View Answer

Answer: c
Explanation: You pass a variable by reference when you want the receiving procedure to change the contents of the variable. To pass a variable by reference in Visual Basic, you include the keyword ByRef before the name of its corresponding parameter in the receiving procedure’s header. The ByRef keyword tells the computer to pass the variable’s address rather than its contents.

26. Which of the following forces a literal constant to assume a data type other than the one its form indicates?
a) Any literal
b) Keyword
c) Literal type constant
d) Literal type variable
View Answer

Answer: c
Explanation: decTex=0.5D statement shows that how you convert a numeric literal constant of Double data type to decimal data type and then assign the result of a decimal variable. The D that follows 0.5 in the statement is one of the literal type characters in Visual basic. A literal type constant forces a literal constant to assume a data type other than the one its form indicates. Here D forces the double number 0.5 to assume the decimal data type.

27. Which of the following is used to display a message box in Visual Basic?
a) MessageBox.Show
b) MessageBox.show
c) MessageBox
d) AlertBox.View
View Answer

Answer: a
Explanation: Application may need to communicate with the user during run time; one means of doing this is through a message box. You display a message box using the MessageBox.Show method. The message box contains text, one or more buttons, and an icon.

28. In Visual Basic, which of the following method converts a string to a number?
a) Convert
b) Tryparse
c) Extern
d) Parse
View Answer

Answer: b
Explanation: The tryparse method converts a string to a number. However, unlike the val function which always returns a double number, the tryparse method allows the programmer to specify the number’s data type. For this reason most programmer prefers to use the tryparse method. Every numeric data type in visual basic has tryparse method that converts a string to that particular data type.

29. Which of the following is used to convert a number from one data type to another in visual studio?
a) Literal constant
b) Object
c) Convert class
d) Parser
View Answer

Answer: c
Explanation: The convert class can be used in any language built in visual studio. Thus they have an advantage of the conversion function; since the conversion function can only be used in visual basic. To convert a number from one data type to another, we generally use the convert class.

30. Which of the following type of constant is ControlChars.NewLine constant?
a) Character
b) Pure
c) Intrinsic
d) Invariable
View Answer

Answer: c
Explanation: Intrinsic constant is one that is built into Visual Basic. ControlChars.NewLine is inbuilt in Visual basic, that is the code for this function, that is its control is already predefined. Thus it is an intrinsic constant.

31. The position of an item in a list box depends on which of the following property of the value stored in the list box’s?
a) Unsorted property
b) Sorted property
c) Descending Property
d) Ascending property
View Answer

Answer: b
Explanation: The position of an item in a list box depends on the value stored in the list box’s Sorted property. When the Sorted property is set to False (the default value), the item is added at the end of the list. When the Sorted property is set to True, the item is sorted along with the existing items and then placed in its proper position in the list. Visual Basic sorts the list box items in dictionary order, which means that numbers are sorted before letters, and a lowercase letter is sorted before its uppercase equivalent.

32. Which of the following returns a value after performing its specific task in Visual Basic?
a) Structure
b) Sub block
c) Sub procedure
d) Function Procedure
View Answer

Answer: d
Explanation: In addition to creating Sub procedures in Visual Basic, you also can create
Function procedures. The difference between both types of procedures is that a Function procedure returns a value after performing its assigned task, whereas a Sub procedure does not return a value. Function procedures are referred to more simply as functions.

33. Which of the following property is used to specify a combo box’s style in Visual Basic?
a) Style
b) ComboBoxStyle
c) DropDownStyle
d) DropStyle
View Answer

Answer: c
Explanation: Three styles of combo boxes are available in Visual Basic. The style is controlled by the combo box’s DropDownStyle property, which can be set to Simple, DropDown (the default), or DropDownList. Each style of combo box contains a text portion and a list portion.

34. What will be the output of the following Visual Basic code?

Dim intScores As Integer = {78, 83, 75, 90}
Array.Sort(intScores)

a) 90,83,78,75
b) 78,75,83,90
c) 78, 83, 75,90
d) 75,78, 83,90
View Answer

Answer: d
Explanation: Array.Sort sorts the array in ascending order. In the question above it sorts the contents of the array in ascending order, as follows: 75, 78, 83, and 90.

35. Which of the following section is used to make text appear around the image?
a) Wrapping style
b) Text style
c) Image properties
d) Align
View Answer

Answer: a
Explanation: Wrapping style makes the text appear around image. In Visual Basic 6.0, the WordWrap property determines if text wraps to multiple lines when it is too long to fit in a label.
In Visual Basic 2008, the text in a Label control automatically wraps. The only way to prevent wrapping is to make the height of the Label control equivalent to a single line of text.


Chapterwise Multiple Choice Questions on Visual Basic (VB.Net)

Visual Basic MCQ - Multiple Choice Questions and Answers

Our 1000+ MCQs focus on all topics of the Visual Basic (VB.Net) subject, covering 100+ topics. This will help you to prepare for exams, contests, online tests, quizzes, viva-voce, interviews, and certifications. You can practice these MCQs chapter by chapter starting from the 1st chapter or you can jump to any chapter of your choice.
  1. Visual Basic Introduction
  2. Visual Basic ToolBox Window
  3. VB.Net User Interface
  4. VB.Net Coding the Application
  5. Visual Basic Variables and Constants
  6. Modifying the Playtime Cellular Application
  7. Visual Basic Selection Structures
  8. Making an Application & Interface Design
  9. Visual Basic Repetition Structure
  10. Visual Basic Sub and Function Procedures
  11. VB.Net String Manipulation
  12. Visual Basic Arrays
  13. VB.Net Structures and Sequential Access Files
  14. VB.Net Classes and Objects
  15. Visual Basic Web Applications

1. MCQ on Visual Basic Introduction

The section contains Visual Basic multiple choice questions and answers on properties window, application starting and ending process.

  • Visual Basic Properties Window
  • Starting and Ending an Application
  • 2. VB.Net MCQ on ToolBox Window

    The section contains VB.Net questions and answers on label tool, picture box tool, buttontool, code editor, timer tool, formborder style, minimizebox, maximizebox and controlbox properties.

  • Visual Basic Label Tool
  • Visual Basic Picture Box Tool and Button Tool
  • Visual Basic Code Editor
  • Visual Basic Timer Tool
  • FormBorder Style, MinimizeBox, MaximizeBox and ControlBox Property in Visual Basic
  • 3. Visual Basic Multiple Choice Questions on User Interface

    The section contains Visual Basic MCQs on user interface buiding, interface border style and autosize properties, access keys assinging and tab order controlling.

  • Building the User Interface
  • Visual Basic Border Style and AutoSize Properties
  • Visual Basic Assigning Access Keys
  • Controlling the Tab Order
  • 4. Visual Basic MCQ on Coding the Application

    The section contains Visual Basic multiple choice questions and answers on application coding using psedocode and flowchart, writing arithmetic expressions, application testing and debugging.

  • Coding the Application Using Pseudocode and Flowchart
  • Writing Arithmetic Expressions
  • Testing and Debugging Application
  • 5. Visual Basic MCQ on Variables and Constants

    The section contains Visual Basic questions and answers on variables data type selection, declaring and assigning data to existing variable, variable scope and lifetime, static variables, named constants, option explict, option inner and strict.

  • Selecting Data Type and Name for the Variable
  • Declaring and Assigning Data to an Existing Variable
  • Scope and Lifetime of a Variable
  • Static Variables and Named Constants
  • Option Explicit, Option Inner and Option Strict
  • 6. VB.Net MCQ on Modifying the Playtime Cellular Application

    The section contains VB.Net MCQs on strings concatenation, inputbox function and tostring method, controlchars.newline constant and designing default button.

  • Concatenating Strings, InputBox Function and toString Method in VB.Net
  • ControlChars.Newline Constant and Designing Default Button in VB.Net
  • 7. Visual Basic MCQ on Selection Structures

    The section contains Visual Basic multiple choice questions and answers on single alternative and dual alternative selection structures, logical operators, selection structures, nested and multiple alternative selection structures.

  • Single-Alternative and Dual-Alternative Selection Structures
  • Visual Basic Logical Operators
  • Visual Basic Strings in Selection Structures
  • Visual Basic Nested Selection Structures
  • Visual Basic Multiple Altenative Selection Structures
  • 8. VB.Net MCQ on Making an Application & Interface Design

    The section contains VB.Net questions and answers on financial.pmt method, messagebox show method, addition of groupbox, radio button and check boxes in the form.

  • Adding a GroupBox to the Form and Using Financial.Pmt Method
  • Using the MessageBox.Show Method
  • Adding a Radio Button & Check Box to the Form
  • 9. Visual Basic MCQ on Repetition Structure

    The section contains Visual Basic MCQs on do loop statement, counters, accumulators, for next statement, list box, refresh and sleep methods in interface.

  • Visual Basic Do Loop Statement
  • Visual Basic Counters and Accumulators
  • For..Next Statement
  • Refresh and Sleep Methods, Including List Box in an Interface
  • 10. VB.Net MCQ on Sub and Function Procedures

    The section contains VB.Net multiple choice questions and answers on passing variables, function procedures and interface.

  • VB.Net Passing Variables
  • VB.Net Function Procedures
  • Including a ComboBox in an Interface
  • 11. Visual Basic MCQ on String Manipulation

    The section contains Visual Basic questions and answers on string working and searching, comparing strings using pattern matching, menu addition to form and mnufilenew object click event procedure coding.

  • Working with String
  • Searching a String
  • Using Pattern Matching to Compare Strings
  • Adding a Menu to a Form
  • 12. Visual Basic MCQ on Arrays

    The section contains Visual Basic MCQs on one dimensional array, for each next statement, parallel and two dimensional arrays, total and average values calculations, arrays, collections, accumulator, counter arrays, searching and sorting of one and two dimensional arrays.

  • Visual Basic One-Dimensional Array
  • For Each..Next Statement
  • Sorting a One-Dimensional Array
  • Visual Basic Parallel & Two-dimensional Arrays
  • 13. VB.Net MCQ on Structures and Sequential Access Files

    The section contains VB.Net multiple choice questions and answers on structure variable declaration, information alignment, writing, closing and reading data of a sequential access file.

  • Declaring and Using a Structure Variable
  • Writing Data to a Sequential Access File
  • 14. Visual Basic MCQ on Classes and Objects

    The section contains Visual Basic questions and answers on oop terminology, class creation, working and reuse, classes that contains parameterized constructor, readonly property, auto-implemented properties and overloaded methods, base and derived class.

  • Object Oriented Programming Terminology
  • Creating a Class
  • Working with Classes
  • 15. VB.Net MCQ on Web Applications

    The section contains VB.Net MCQs on web applications and dynamic web pages.

  • Web Applications
  • Dynamic Web Pages
  • If you would like to learn "Visual Basic (VB.Net)" thoroughly, you should attempt to work on the complete set of 1000+ MCQs - multiple choice questions and answers mentioned above. It will immensely help anyone trying to crack an exam or an interview.

    Wish you the best in your endeavor to learn and master Visual Basic (VB.Net)!

    advertisement
    Manish Bhojasia - Founder & CTO at Sanfoundry
    Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

    Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.