Sep 25, 2009

What is a Variable

a variable is a container that has a name and holds some value at the end. In VB.NET you dimesion variables before you can start using them. The dimensioning process simply tell VB.NET that you want a variable before using it.
VB.NET allocates a space in memory for each variable you dimension so that you can put there whatever you like. However since VB.NET does not know what you want to store, you have to give to the variable a datatype which restricts what you can store in this variable.
 
Datatypes keep VB.NET and you in harmony. Since the computer has to make special arrangement for the space in memory based on whether it will store a string of text, a numerical value or may be even a picture.
 
There is a lot of datatypes to choose from but I will explain these most commonly used one's before.
Integer: It is a variable type that allows you to store numerical values without a decimal point that range between  -2,147,483,648 to +2,147,483,647. Mostly commonly used as a counter for something like this example.
Dim NumberOfChildren as integer = 5
Boolean:  It is a variable type that allows you to store one of two values (true or false) used to indicate a status. For example
Dim HasChildren = True
DateTime: This is a variable type that allows you to store date and time information as accurate as it can be up to the ticks of the second. An Example would  be
Dim CurrentMoment as DateTime = Now()
Double: This variable will be able to store numerical values of all sizes approzximatly. It can store numbers with decimal point also. the range of values is 5.0 x 10-324 to 1.7 x 10308 which is a pretty long range for you. An example would be
Dim SolarDistance as Double
Decimal: When dealing with some banking issues decimal proves to be more useful when you want a precise number of decimal places. It's not as accurate as the Double Type, though.
Dim Balance as Deicmal = 18732.321
String: Very useful in storing large amount of text. It is able to store a unicode string with a maximum length of 2,147,483,647 characters. I think that this is enough to store any type of text you have (except if we are talking books)...
Dim FullCustomerName = "Nidal Bin Hasan Bin Ahmed Bin Tarek Bin Omar Bin Enough"
 
You can see from this succint list that VB.NET has the power to store any type of variables that you have (you will see different types in the future).
 
There is a nice addition to these variable with .NET 3.0 which is the nullable data type. I will be posting another entry about them.
 
See you in a later blog post.
 

No comments: