Visual Basic Programming
Created | Updated Jan 28, 2002
Introduction
The Visual Basic programming language (or VB, as the pros call it) is a language developed by Microsoft, a part of their Visual Studio family of programming languages. As the name suggests, it is very similar to to the original BASIC1 language2, but it is Object Orientated3, unlike the original BASIC language. Also, as the other part of the name suggests, you don't have to worry about the graphical side of the program4 when you are programming, as the compiler does it all for you.
The flavours of Visual Basic
Currently, there are three main 'flavours' of the Visual Basic programming language:
- The full blown programming product
- Visual Basic for Applications (VBA)
- Visual Basic Script
Essentially, they are all the same language, but each of them have slightly different purposes. The full blown programming product is used for making standalone programs (like Microsoft Word, Excel, etc.) Many Microsoft programs now offer the ability to program in VBA to make repetitive tasks easier. You can write short programs (called Macros) to do number crunching, and other boring jobs; and finally, VBScript is a scripting language (a bit like JavaScript), used for programming browser based applications. VBScript is a rather cut down version of the full Visual Basic language, but it has the advantage that, if you know VB, you can take up VBScript very easily.
Learning Visual Basic
Is it easy to learn?
VB is easy to learn, in that it is closer to human language than other programming languages such as C. In fact, the code bears some kind of resemblance to English, whereas languages like C and Java look quite frightening at first sight.
Look at this example of some VB code:
If number<7 Then
TextBox.text="Number is smaller than 7"
Else
TextBox.text="Number is bigger or equal to 7"
End If
... and compare with this C code which (nearly) does the same thing:
if (number<7)
{
printf("number is smaller than 7");
}
else
{
printf("number is bigger or equal to 7");
}
OK, so where do I start?
There are many excellent books out there which teaches you Visual Basic, but they tend to be rather costly. The IDE5 for VB costs a lot in itself, and the chances are that you wouldn't want to spend more money on expensive books. Well, HELP is at hand! Use the Help files which came with your copy of Visual Basic.
Now, this may seem like a stupid suggestion, as Help files don't tend to be particularly user-friendly, but atleast it comes to the point, unlike some books in which the author rambles on about the last time he did this, and the last time he did that, etc.... you know the type. Infact, I learnt Visual Basic from helpfiles alone.6The later versions of Visual Basic (I think from version 5 onwards) also comes with a nice manual called Visual Basic Books Online, which has a more tutorial-like approach.
The Basics Of Visual Basic
OK, so I can't teach you the whole of Visual Basic on this page alone (I wouldn't have the patience to anyway), but, here is a taster. I am assuming that you have got a copy of Visual Basic (if you don't, then you can't do anything).
Hello World (or Universe, or Life, or Everything, depending on your mood)
So, let's start with what all programmers start with: The legendary 'Hello World Program'. All this does is to write 'Hello World', anywhere on the screen. The point of it is to introduce the programmer to the new programming language. So, here it goes:
- Open up Visual Basic. You should be greeted with a blank form
- Make a textbox (Click on the textbox button on the toolbox, and draw a rectangle on the blank form)
- Make a button (in the same way as the textbox, but click the 'Command Button' button on the toolbox instead)
Double click the button. - Type the following code in between 'Sub ....' and 'End Sub':
text1.text="Hello World"
- Close the code window
- Click the 'RUN' button on the toolbar at the top
- Click the button on the form
The text box should display 'Hello World'
Where do I go from here?
Well, you are now free to do anything you want (well, not quite anything). Here are some sites which may be of use:
Microsoft Developer Network | http://msdn.microsoft.com |
A1VBCode | http://www.a1vbcode.com |
VB Wire | http://vbwire.com/ |
VB CodeGuru | http://codeguru.developer.com |
The best way to learn is to explore, so go ahead! And Bon Chance