Variable Declaration Exercise
Write an appropriate Visual Basic declaration statement to define variables to store the following information. Be sure to use appropriate prefixes. I have completed the firs one for you.
Variable Name should begin with a three character lowercase prefix which identifies the data type that will be used followed by a descriptive name that begins with an uppercase character.
|
Information |
Declaration |
|
1. Age |
Dim intAge as Integer |
|
2. Address |
Dim strAddress as String |
|
3. FICA tax withheld |
Dim decFICA as Decimal FICA tax withheld is a dollar amount which is usually something like 25.45. Because of the cents it must be stored in a floating point data type, like Decimal. |
|
4. GPA |
Dim decGPA as Decimal GPA (Grade Point Average) is on a scale of 1 to 4 or 5 and includes a decimal - like 4.5 is a B+. It must be stored in a floating point data type, like Decimal |
|
5. Marital status |
Dim strMarried as String Since Marital Status could be Married, single, widowed, divorced a Boolean data type is probably not sufficient. String would be a better choice |
|
6. End of month flag |
Dim blnMonthEnd as Boolean Since this is a flag it should be Boolean |
|
7. Social Security number |
Dim strSSNumber as String Since SS# is not a quantity and contains symbols other than numbers it should be declared as a String |
|
9. Telephone number |
Dim strPhoneNumber as String Since a phone number is not a quantity and contains symbols other than numbers it should be declared as a String |
|
11. Account closed indicator |
Dim blnAcctClose as Boolean Since this variable is an indicates whether an account is closes or not, it should be Boolean |
|
12. Interest rate |
Dim decIntrest as Decimal An interest rate is typically a percentage (.0975) and therefore should be stored in a Decimal |
|
13. Number in stock |
Dim intStock as Integer Usually the number in stock is a whole number Short is as appropriate as Integer as long as the inventory does not exceed 32,767 |