Correct / Incorrect Assignment Statements Answers

 

Given the following variable declarations

 

Dim strPhone as string

Dim intAge as Integer

Dim blnHourly as Boolean

Dim decRate as Decimal

Dim decHours as Decimal

Dim decGrossPay as Decimal

 

Are the following assignment statements correct or incorrect?  Why?

 

Assignment Statement

Valid?

Invalid?

strphone = 345-4565

 

Invalid. The phone number should be in quotation marks

Int  Age = 35

 

Invalid. There is a space in the variable name.

“342-2222” = strPhone

 

Invalid. Only variables or properties maybe on the left side of and assignment operator. The statement needs to be reversed. 

Let strPhone = “342-2222”

 

The word “Let” is optional

blnHourly = True

Valid

 

strPhone = “342-2322”

Valid The quotation marks are required because the phone number is a string

 

decRate = “5.0”

 

Invalid. “5.0” is a nonnumeric constant. You must not assign nonnumeric values to numeric variables.

decRate = 5

Valid

 

decHours * decRate = decGrossPay

 

Invalid. Only variables or properties maybe on the left side of and assignment operator. The statement needs to be reversed.

 Let sngGrossPay = sngHours * sngRate

decGrossPay = decHours * decRate

valid