People with no previous programming experience will find that Visual Basic is the best place to start. Progressively harder languages such as C, C++ and Assembler will fill the other rungs of the ladder but for now you must not set your targets to high. By all means set yourself a goal or "carrot" - that always helps when learning a language, you may never accomplish that goal but the experience gathered by trying to reach it is invaluable.

This section is aimed at complete novices, people with previous programming experience are welcome to follow this tutorial but I doubt it will teach them anything they don't already know. In my opinion, the hardest part of learning a programming language is getting your head round the structure of it. I'm afraid that no book or tutorial can teach you this - as you program more and more you will develop your own programming style and soon the structure of the language will become second nature to you.


Part One - What the 'eck is this?...

First things first, find your nearest Chinese takeaway and note down its phone number. I am going to use Visual Basic 3.0 for the tutorial because I believe it is a lot better to learn with than Visual Basic 4.0.

Ok, you must have seen the following lines before:

10: print "Hello World!" 20: goto 10
Yes? Of course you have! For those of you that are unsure of its meaning then don't worry because VisualBasic is nothing like the above. Firstly, VisualBasic does not use line numbers. This is I think the biggest difference between it and BASIC as was; QBasic, Speccy Basic, GFA Basic etc. Once you get used to not using line numbers then you're over the first hurdle. Secondly, it is very rare that you see a print statement used in VB. VB is what it is - Visual, you use it to create Microsoft Windows compatible applications, output to the screen is through labels and text boxes which are drawn onto your form "visually" by yourself. I will explain this by re-writing the above code in VisualBasic, this can be done in two ways:
Part One - Your first likkle program!...

Now would be a good time to order your Chinese takeaway. I learnt to program by example, unfortunately I didn't have anyone to help me like you have me!. By the end of this tutorial you should have a working VB application that you can call your own. "What type of program?" I've decided we'll write an image viewer, yup - nothing too complicated to start off with. Don't worry, I'll explain each section of the code as we go along.


Part One/Step One - Design...

Ok, lets start up VisualBasic 3.0 so we get a clean, blank form to work with. Drag a Directory List box onto your blank form, drag a Drive List box onto the form and place it underneath the Directory List box. Drag a File List box and put it to the right of the Directory List Box. Drag a command button onto the form and place it underneath the File List Box, change its caption to "View" by highlighting it and pressing F4 and altering the "Caption" property. Finally drag a Picture Box onto the form and place it to the right of the File List box. Ok, we have our main screen all ready, it should look something like this:

Notice that my layout resembles a Windows Open/Save dialog. Where possible in our applications we should try and maintain a standard; the result is the user of our program can learn it quicker and operate it faster. Righto then, onward to the next part.



Part One/Step Two - Drive list...drive list...where for art thou file list??...

This is going to be hardest part of this tutorial. I beg you to try and understand what the code does rather than just slapping it into the controls and pressing F5. If you do the latter then you're wasting your time. Don't look at me like that! Its easy honest...lets move on.

Well at the moment our little utility is pretty useless, it does nothing at all. We need to make the Directory, Drive and File listboxes interact with each other just like a proper Windows File dialog. Here's how we do it and its incredibly simple:

Press F5 to see how the program performs. Try changing drives and directories and see what happens.

Part One/Step Three - Mummy! Mummy! I want my piccy!

This is where it gets tricky. We now need to get the selected filename, check that it is a valid Bitmap file and then load it into the Picture box. Lets press on.

Now, if we press F5 to see how our application is doing we should be able to move around our hard drive, find a bitmap file (a file ending in BMP), be able to double click on it and it will be displayed in the picture box. If we click on a file that isn't a BMP the application will tell us we've done wrong but let us continue selecting files. Almost there now folks, honest!

Part One/Step Four - My mouse won't double click!...

We're nearly at the end of the program as well as our Chinese takeaway. Remember we created a command button? Well its time to make it do something. The button will do exactly the same as double-clicking on a file would do, some people find a button easier to use and I want to show you a nice trick as well. To make the button display the picture in exactly the same way as double clicking on the filename in the File Listbox:

Yes! Thats it! We could write the whole code out again in the Command1_Click event but whats the point when we've already written the code somewhere else? All we do is harness that code by telling the application to jump to the File Listboxs' double click event and execute the code there.

Part One/Step Five - Yusssss!

Celebrate wildly by dancing round the room in a bikini with a bowl of fruit balanced on your head. Procede to force your program onto everyone that owns a computer and let them know that you are a programmer - almost ;-)

If you're game, you may want to move onto the Visual Basic 4.0 Tutorial...go on, I dare ya!