A Visual Basic program consists of a series of statements and there are really only three kinds:
We'll take a more detailed look at these next.
- Assignment Statements
This is just making one thing equal to another:
myVariable = myOtherVariable + aFileVariable
Visual Basic also supports assignment operators such as *= and &=. This simply combines an assignment with a operation. The operator &= is the same as a = a & b.
This can be something like starting a programming loop:
For i = 1 To 10
more statements
Next
Or calling a method somewhere else in the program:
DoThisInterestingMethod(myVariable, myOtherVariable)
Methods will be covered extensively when we discuss Object Oriented Programming again.
Variables, Constants, and Arrays
All programs need data to work with. Data is stored in variables and constants while a program is working on it. A variable is just a name attached to part of computer memory that you can change. A constant is a name attached to computer memory, but it's protected from being changed. You use the Dim statement, or one of several others that control where the variable will have meaning in the program (called the Scope of the variable - Public, Private, Protected, Friend, or Protected Friend). Here's a variable declaration.
Dim MyVarName As String
One of the big differences between languages is the types of data that are supported. For example, whole numbers such as 1, 2, 3, -8759 and 14589729 are called integers and nearly all languages will support some form of integer. But not all languages will store them in computer memory the same way or support all possible integers. An integer in Visual Basic 6 is will occupy 16 bits (the smallest unit of data, a 1 or a 0) of memory - equivalent to 2 bytes of memory - and can only store numbers in the range from -32,768 through 32,767. In all Visual Basic .NET languages, including VBE, a integer will occupy 32 bits of memory - 4 bytes - and can store numbers from -2,147,483,648 through 2,147,483,647. In addition, there are at least three kinds of integers in .NET (short, integer, and long) and more if you start counting things like the Byte data type that can technically store an integer as well.
VB Express gives you a broad range of data types that you can use in your program to store not only numbers, but characters (ordinary text), dates, true or false (Boolean) or floating point numbers. (A floating point number uses a base, like 1.23 where the number of digits is the same, and then multiplies this base by a power of ten - for example 10, 100, 1000, or .001 - to get larger or smaller values. The net effect is that the decimal point can "float" forward or backward.) There is also an Object data type that you can store anything in and a User-Defined data type. (This is actually a Structure.)
There is only one datatype worth mentioning that VB.NET does not support and that's one that was quite well known in VB 6 and a few earlier versions: the Variant data type. Earlier versions of Visual Basic made it easy to just start using a variable without bothering to decide what type of variable it was. This was one of the "features" of VB6 that made it unpopular with a lot of professional programmers. It turns out that this carefree way of coding can result in some nasty bugs and will also make the code run slower. In VB.NET, you can use the Object data type in a similar way but it's strongly discouraged (Object is provided for an entirely different reason) and performance is even worse.
You can also create a name for a whole Array of data with a single name using a declaration like this:
Dim myArray(10) As String
This declaration lets you store 11 (not 10, the array starts with 0) character strings (A character string is just text like, "My dog is named Spot.") and reference them by their place in the array (like myArray(4) to use the 5th one).
There are lots of other more advanced ways to deal with data, such as enumerations, collections, and structures. Check MSDN for the specific details about declaring variables and constants. The key thing to remember right now is that you should declare a meaningful name for every piece of information that you will use in your program.
The main thing that a statement will contain is an operation that "does something" with information (that is, data). So we discuss operations on the next page.

