Visual Basic Questions and Answers – Declaring and Assigning Data to an Existing Variable

«
»

This set of Visual Basic online quiz focuses on “Declaring and Assigning Data to an Existing Variable”.

1. An __________ statement is used to assign a value to an existing variable.
a) Arithmetic
b) Relational
c) Logical
d) Assignment
View Answer

Answer: d
Explanation: An assignment statement is used to assign a value to an existing variable during run time. It is also used to add value to control property during runtime. The syntax for doing so is varName=expression, where expression can contain items such as literal constants, object properties, variables, keywords or arithmetic operators.
advertisement

2. A __________ is an item of data whose values do not change while the application is running.
a) Literal constant
b) Variable
c) Auto variable
d) Extern variable
View Answer

Answer: a
Explanation: A literal constant is a value of data, whose values does not change while the application is running. The values of the constants remain same throughout the application. Trying to change the value of the constant results in a syntax error. Anything can be a constant value i.e. a string, number, etc. can be constant.

3. The data type of the value assigned should be same as __________
a) Any constant defined in the application
b) The variable itself
c) Can be anything
d) Any extern defined in the application
View Answer

Answer: b
Explanation: the data type of the value assigned to a variable should be same as the variable itself, i.e. assigning sting to a numeric data type will result in an error. int a =”mary” is erroneous.

4. The string literal are enclosed in __________
a) Quotation mark
b) Question mark
c) Exclamation mark
d) Dollar mark
View Answer

Answer: a
Explanation: The string literal variables and constants are enclosed in quotation mark whereas the numeric literal variables and constants are not. The quotation mark differentiates a string from number and variable name.

5. While entering a numeric literal constant you need not enter a __________
a) Number
b) Special character
c) Character
d) Double variable
View Answer

Answer: b
Explanation: When entering a numeric literal constant you do not enter a comma, or special characters such as dollar sign or the percentage sign. If you want to include a percentage in the assignment statement, you do so using its decimal equivalent for example you enter 0.03 instead of 3%.
advertisement

6. A __________ forces a literal constant to assume a data type other than the one its form indicates.
a) Literal type constant
b) Literal type variable
c) Any literal
d) Keyword
View Answer

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

7. A variable can store __________ value at a time.
a) Only one
b) More than one
c) Only two
d) More than two
View Answer

Answer: a
Explanation: A variable can store only one value at a time. When you use an assignment statement to assign another value to the variable, the new value replaces the existing value.

8. The __________ method converts a string to a number.
a) Tryparse
b) Parse
c) Convert
d) Extern
View Answer

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

9. If the tryparse method determines that the string cannot be converted to the data type, it assigns __________ to the variable.
a) -1
b) 1
c) 0
d) 2
View Answer

Answer: c
Explanation: The tryparse method parses its string argument, which means it looks at each character in the string, to determine whether the string can be converted to the number of the specified data type. If the string can be converted the tryparse method, converts the string to the number and stores the number in the variable specified. If the tryparse method determines that the string cannot be converted to the appropriate data type, it assigns 0 to the variable.
advertisement

10. To covert a number from one data type to another, you use the __________
a) Convert class
b) Parser
c) Literal constant
d) Object
View Answer

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

Sanfoundry Global Education & Learning Series – Visual Basic.

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

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!

advertisement
advertisement
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn