Visual Basic Questions and Answers – Option Explicit, Option Inner and Option Strict

This set of Visual Basic Multiple Choice Questions & Answers (MCQs) focuses on “Option Explicit, Option Inner and Option Strict”.

1. In Visual Basic, if you keep a variable undeclared, it is automatically taken as___________ data type.
a) Int
b) Char
c) String
d) Object
View Answer

Answer: d
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.

2. __________ prevents you from using undeclared variable in your code.
a) Option Explicit On
b) Option Implicit On
c) Explicit Off
d) Implicit Off
View Answer

Answer: a
Explanation: Because it is so easy to forget to declare a variable, or so easy to misspell a variable’s name while coding, thereby inadvertently creating an undeclared variable, visual Basic provides a way that prevents you from entering undeclared variable in your code. You simply enter Option Explicit On in the General Declaration Section of the code editor window. The statement tells the code editor to alert you if your code contains a name of a undeclared data type.

3. __________ ensures every variable and named constant is declared with a data type.
a) Option Infer Off
b) Option Infer On
c) Option On
d) Option off
View Answer

Answer: a
Explanation: When you enter the Option Infer Off statement in the General Declaration Section, the Code Editor ensures that every variable and named constant is declared with a data type. In other words, the statement tells the computer not to infer a memory location’s data type based on the data assigned to the memory location.
advertisement
advertisement

4. __________ is used to fit the value of the data type to that of the memory location, implicitly.
a) Implicit type conversion
b) Explicit type conversion
c) Convert method
d) Conversion function
View Answer

Answer: a
Explanation: The data type of the value assigned to a memory location should be same as the memory location itself. If the value’s data type does not match the memory location’s data type, the computer uses a process called implicit type conversion to convert the value to fir its memory location.

5. When a value is converted from one data type to another and can store numbers with greater precision, the value is said to be __________
a) Imported
b) Exported
c) Promoted
d) Précised
View Answer

Answer: c
Explanation: When a value is converted from one data type to another data type, which can store either large numbers or numbers with greater precision, the value is said to be promoted. For example, while processing, Dim sales as Double=9, the value 9 will be converted from integer to double as 9.0; thus this value is said to be promoted.

6. When a value is converted from one data type to another and can store numbers with less precision, the value is said to be __________
a) Demoted
b) Promoted
c) Exported
d) Converted
View Answer

Answer: a
Explanation: When a value is converted from one data type to another data type, which can store either small numbers, or numbers with less precision, the value is said to be demoted. For example, Dim store as Integer=7.4, the value 7.4 is rounded off that is the decimal part is truncated and stored as 7, that is it is converted from double to integer; thus the value is said to be demoted.

7. You can eliminate the problems of implicit type conversion, with the help of __________
a) Option Strict On
b) Option Strict Off
c) Implicit Off
d) Explicit On
View Answer

Answer: a
Explanation: Data loss can occur when a value is changed from one data type to narrower data type that is data type with less capacity. We can eliminate such problems of implicit type conversion, with the help of Option Strict On statement in the General Declaration of the Code editor Window. When the Option Strict On appears on the application window, the computer uses the type conversion rules.
advertisement

8. Option Strict On disallows conversion of String data type to __________ implicitly.
a) Double
b) Object
c) Character
d) Array
View Answer

Answer: a
Explanation: Option Strict On disallows conversion of string data type to Double data type. You need to use the Tryparse method to explicitly convert a String to a Double data type.

9. Option Strict On disallows conversion of Double data type to __________ implicitly.
a) Double
b) Object
c) Character
d) String
View Answer

Answer: d
Explanation: Option Strict On disallows conversion of double data type to string data type. You need to use the Convert class method to explicitly convert a String to a Double data type.
advertisement

10. Instead of entering the Option statements in the Code Editor window, you also can enter in the __________
a) Properties window
b) Project Designer Window
c) File Manager
d) Project Manager
View Answer

Answer: b
Explanation: Instead of entering the Option statements in the Code editor Window, you can also enter in the Project Designer window or Options dialog box. But it is strongly recommended that you enter the option statement in the code editor window, because doing so ensures that the options are set appropriately; it also makes your code more self-documenting.

Sanfoundry Global Education & Learning Series – Visual Basic.

To practice all areas of Visual Basic, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
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.