Programming

So far, all we've been doing is making (very pretty) windows. They don't actually do anything, though. That's where code comes in.

Code is just a set of instructions that you give the computer, telling the computer what you want it to do. Every control has at least a dozen "procedures", or chunks of code, behind it; each procedure corresponds to a different event which that control can fire.

If you want to see the code that's sitting behind a control, just double-click on it. Up will pop the Code Window.

The Code Window

The Code Window is split into two parts. The main part is a plain text window, in which you can enter code. At the top are two drop-down Combo Boxes. The left one lets you select any of the controls on your form, and the right one lets you select any one of the procedures for the selected control.

Variables

Note that if you need to save any information temporarily (say, the salary of the user), you can do so in a variable. A variable is just a chunk of memory that you give a name to. So you could set aside a chunk of memory to hold the user's salary, and call that chunk of memory TheSalary. From then on, in code, you could refer to TheSalary, and Visual Basic would know to refer to that chunk of memory.

Visual Basic does not treat variables with case sensitivity. Thus TheSalary = thesalary = THESALARY.

You can also set up an array, which is a large chunk of memory set aside for a lot of variables, all with the same name. So you could set up an array of 10 numbers, calling that array StaffSalary. The advantage of this is that you can access each one very easily, without having to refer to separate variables, say, StaffSalary1, StaffSalary2, StaffSalary3, etc.

One important thing about Visual Basic is that you must change the names of your controls before you start coding! The reason is that as soon as you change the name of a control, any code that you've written for that control gets copied to another part of the project, and all the space for code in the newly-named control is blank. Don't ask me why this is; it just is. Moral of the story: change the names of all your controls before you add any code.


The Intro to Visual Basic homepage is hosted by GeoCities