You are here:

Visual Basic/Visual Basic (Programming)

Advertisement


Question
Would you mind helping me please?

Instructions say: Write a Dim statement for each of the following variables using the variable name that would be best for each value.

a. The population of the state of Alaska

b. Your weekly pay

c. The smallest data type you can use for your age

d. A constant for the first initial of your first name

e. The minimum wage

f. The name of the city in which you live

g. The answer to a true/false question

Answer
Dear Derek,

The common rule to Name variables is to give them meaningful names, like for the name - strName with String type, for somebody's age - NumOfYears with one of the numerical types: Double, Integer etc. You can choose yourself anything just meaningful. Let's look at a: population cannot be Double or String or Decimal - it's only Integer or Long (for really big numbers).  There are not that many people in Alaska so it's Integer. So for a - just out of my mind - this is the statement:

Dim iPopulationOfAlaska As Integer

the variable name is starting with i - so if you happens to see iPopulationOfAlaska in code you already know it is an Integer. Common is to use str prefix for String variables, dbl for Double, lng for Long, dec for Decimal.

Using the same common sense those are my suggestions: again you can choose something different, but it should be meaningful.

b. Dim dblMyWeekPay As Double

c. Dim byteMyAge As Byte (Byte is in the range from 1 to 256)

d. Const strMyFirstInitial As String = "D"

(as you can see there is a special statement "Const" to define constants)

e. Dim dblMinWage As Double

f. Dim strMyCity As String

g. Dim bAnswer As Boolean



Regards,

Vitaly

Visual Basic

All Answers


Answers by Expert:


Ask Experts

Volunteer


VITALY

Expertise

Area of expertise is Visual Basic .NET (VS 2008 and Framework 3.5) design and development for Windows applications. You can ask me any Visual Basic questions and some questions about .NET Framework. You can also ask me how to use Component One controls in Visual Basic. Do not ask me questions about Web design and development in Visual Basic.

Experience

I'm working as VB programmer from 1997, so I have a lot of experience with Visual Basic .NET as well as Visual Basic 6. Area of expertise is Visual Basic .NET (VS 2008 and Framework 3.5) design and development for Windows applications; Component One controls for Visual Basic; User controls; Moving VB6 applications to .NET.

Education/Credentials
B.S. in Computer Science

©2016 About.com. All rights reserved.