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.
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.
2. A __________ is an item of data whose values do not change while the application is running.
a) Literal constant
c) Auto variable
d) Extern variable
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
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
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 __________
b) Special character
d) Double variable
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%.
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
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
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.
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.
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.
10. To covert a number from one data type to another, you use the __________
a) Convert class
c) Literal constant
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.
- Apply for Computer Science Internship
- Practice Computer Science MCQs
- Buy Visual Basic Books
- Apply for Visual Basic Internship
- Buy Computer Science Books