You can name your variable almost anything you want as long as it starts with a letter and is not a reserved word.
Boolean: A Boolean variable can only hold one of two values True or False. Booleans are declared and assigned as:
Integer: An integer holds only whole numbers. For example an integer can be assigned a value of 5 but try assigning 5.5 and an error will be thrown.
VB.net has three different size integers Int16, Int 32, & Int64. The number after int refers to the size of the integer in bits. So a 16 bit integer has a maximum value of 1111111111111111 base 2 which is 65535 in base 10 (The standard we are all used to.) So if you assign a value over 65535 or under -65535 to a variable declared as an int16 it will throw an overflow error. So for larger numbers you will need to declare them as int32 or int64, but only if it is necessary as this will cause your program to take up more memory. Integers are declared and assigned as follows:
Singles and Doubles will both hold numbers with or without decimal places. The only difference is a single is 4 bytes and a double is 8 bytes. They are declared as follows:
A char variable holds only one character. For example a char can be assigned "a" but not "apple". A char is defined as follows:
A string can hold multiple characters. It is used much more often than a char. Strings must be enclosed in quotes. Declare and assign strings as follows:
There is also the matter of where to declare your variables. If you want to declare a local variable it should be declared in that local sub procedure or function and it will be cleared from the RAM when the procedure is finished executing. If you declare a global variable declare it at the top of the class. It can be accessed by any sub procedure or function in that class it will be retained in memory until the class is unloaded if the class is a form it will be unloaded when the form is closed. You can also declare a global variable in a module which will be retained in memory until the entire program stops executing and can be accessed anywhere in your program.
If you use dim you are making a private variable that can only be accessed in the same class it is declared in if you declare a variable using Public it is a public variable that other classes can access.
Programmer
Country: USA ~
Posts: 161 ~
Member Since: 10/16/2008 ~
Last Visit: 09/08/2010