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

1.

An __________ statement is used to assign a value to an existing variable.

   A.) Arithmetic
   B.) Assignment
   C.) Relational
   D.) Logical

Answer: Option 'B'

Assignment

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.

DigitalOcean Referral Badge

2.

A __________ is an item of data whose values do not change while the application is running.

   A.) Literal constant
   B.) Extern variable
   C.) Variable
   D.) Auto variable

Answer: Option 'A'

Literal constant

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.

DigitalOcean Referral Badge

3.

The data type of the value assigned should be same as __________

   A.) Any constant defined in the application
   B.) The variable itself
   C.) Any extern defined in the application
   D.) Can be anything

Answer: Option 'B'

The variable itself

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.

DigitalOcean Referral Badge

4.

The string literal are enclosed in __________

   A.) Quotation mark
   B.) Question mark
   C.) Exclamation mark
   D.) Dollar mark

Answer: Option 'A'

Quotation mark
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.

DigitalOcean Referral Badge

5.

While entering a numeric literal constant you need not enter a __________

   A.) Number
   B.) Special character
   C.) Double variable
   D.) Character

Answer: Option 'B'

Special character

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%.

DigitalOcean Referral Badge

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.) Keyword
   D.) Any literal

Answer: Option 'A'

Literal type constant
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.

DigitalOcean Referral Badge

7.

A variable can store __________ value at a time.

   A.) More than two
   B.) More than one
   C.) Only one
   D.) Only two

Answer: Option 'C'

Only one

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.

DigitalOcean Referral Badge

8.

The __________ method converts a string to a number.

   A.) Tryparse
   B.) Parse
   C.) Extern
   D.) Convert

Answer: Option 'A'

Tryparse

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.

DigitalOcean Referral Badge

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

Answer: Option 'C'

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.

DigitalOcean Referral Badge

10.

To covert a number from one data type to another, you use the __________

   A.) Literal constant
   B.) Parser
   C.) Object
   D.) Convert class

Answer: Option 'D'

Convert class

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.

DigitalOcean Referral Badge

Declaring and Assigning Data to an Existing Variable - Visual Basic Questions and Answers Download Pdf

Recent Posts