Like in math, we need a place to store numbers. That is where variables for the type short, long, integer, and double are used.
short: Limited to being between -32768 and 32767long: Limited to being between -2147483648 and 2147483647integer: Limited to being between -2147483648 and 2147483647double: Limited to numbers with decimals
The main difference between the different types is that they use different amounts of memory. In most cases short variables will suffice, unless you are working with really big numbers. Most people seem to default to integers since memory is not very limited any more, yet I still like to use shorts whenever possible.
Now what if you need to declare something other than a number? What else can variables store? Strings of characters are another common thing for programmers to store. A string in simply a list of characters that make up text.
This is a string.There are to variable types that can store characters:
Char: Stores one character.String: Stores an array of characters.
Again, the difference of the two types above is that the memory required to store one character and storing a list of them is very different. Most commonly a string is used verses a char.
Sometimes you may need to keep track of whether something is true or false. This is the core of a computer system relating directly to the binary in which it operates. As a variable, we call them of the type boolean. Any variable of the type boolean can store a value of either true or false.
Additional, you can store advanced objects into variables. Advanced objects are ones that you create using classes and structures. While these advanced variables might not seem very useful at first as you begin programming, later with more advanced programs you will find that they are very useful and save a lot of time.
Structures: As the name implies, a structure is an object that contains things, much like a house or a building does. While these things are not like those of a house, they are important to the programmer. The structure is a collection of other variables, like shorts and strings. The big difference between the basic variables and a structure is that a structure holds much more information then a basic variable.
Classes: A more advanced structure is called a class. Each class is similar to a structure as they hold many different variables, but in addition a class also can hold subroutines and functions that can be used to ensure that the data stored in the class is correct. This is very handy when it comes to classes that store calculated data by having the calculations occur automatically when a new object is dimensioned.
Visual Basic:
Dim number as shortDim trueFalse as booleanDim myText as string
Structure customStructureDim name as stringDim age as shortDim phoneNumber as stringEnd StructureDim myStructure as New customStructure
Public Class customClassDim name as stringDim age as shortDim phoneNumber as stringSub New(name as string, age as short, phoneNumber as string)Me.name = nameMe.age = ageMe.phoneNumber = phoneNumberEnd SubEnd ClassDim myClass as New customClass