| Learn Visual Basic |
| Difficulty: |
by Lorenzo Dalla Vecchia
(thanks to Fred Wilson for helping me with
grammar/spelling)
Welcome to my Visual Basic tutorial. In this course I will introduce you to the Visual Basic world, as well as to general aspects of programming. I you have already worked with other programming languages, you will immediately get familiar with the Visual Basic environment; if you have never programmed before, that's also fine.
What it is
Visual Basic (also called VB)
is basically a program that lets you create any other Windows program. Formally it is
known as a programming environment.
VB was originally created by Microsoft in 1991 and, from then on, many newer
versions followed. The latest version currently available is the 6.0 version. The most
recent versions (4.0, 5.0 and 6.0), can create 32-bit applications, that will run
under Windows 95, 98, ME, XP and Windows NT/2000; these tutorials apply
to the 32-bit versions of VB.
I strongly advise you to have a copy of VB to work with while you read this tutorial: remember that the best way to learn is to practice. You can find Microsoft Visual Basic at any good computer shop; it would be better to get the latest version, but you can save money by buying version 5. An important thing: you will find 3 editions of VB, differing in price, that let you do different things; here they are in detail:
If you need further information about VB, please refer to
Microsoft Visual Basic official
website.
Got your copy of VB? Ok, let's start.
First look at VB
I assume you have already installed Visual Basic. If not, follow the procedure you would use for any Windows program.
The procedure to start VB is as simple as a couple of mouse clicks.
You will be presented with a screen similar to the following.

It is the IDE (acronym for Integrated Developing Environment), an interface that integrates all the tools needed to design, write, build and test a new application. It can be disorienting at first, but you will soon get used to it.
The major part of the screen is occupied by the Form View area: it is surely the most important, because in that area takes place the action of designing and writing code for your application. A Form, in VB terminology, is just a window or dialog box; as you can see, VB has already created a blank form (Form1) for you to start designing.

On forms, you put controls. Controls are part of the interface of a program: plain text, textboxes, images, buttons, scroll bars and many more. You can see a list of available controls (represented by icons) on the left of the Form View area: that is the Toolbox.

The above picture shows you the Toolbox with general controls: it's not important that you understand the meaning of each control now: Instead, let's see how you can add a control to the form. Do the following:
Now that you have a control on the form, you may want to adjust its size and position: to move a control, just select it and drag. To resize a control, first select it and then drag the size handles (the 9 blue squares around the control) to adjust its size. If you want to delete a control, select it and press the DEL key on the keyboard.
| To select the form you are working on, click on a blank area on the form itself. |
Have you noticed that you can't actually type into the textbox as you would do with any Windows textbox? That's because you are in design mode (look at VB title bar): in the design mode or at design time you just create your application.
To see how your application will behave when run, start it by selecting the
Run button from the Toolbar on the top or by pressing F5
on your keyboard.
In run mode or, as programmers say, at
runtime, your application behaves exactly like the finished application; try typing
inside the textbox you created before. To stop your application, just close the form with
the close button (
) and you will be brought back to design
mode.
Ok, that is enough for a "first look" at Visual Basic. Go on playing with the other controls and get used to the actions of creating, moving, resizing, deleting and also testing your finished application.
The properties of controls
Now that you're familiar with controls, you will probably ask yourself how to customize them. For example, how do I change the text displayed on a button? This is done through control properties.
In the VB World, a property is just a
characteristic of a control: its text, its color, its font, ... etc.
While you are at design time, you can change properties of controls by
using the Properties window, at the bottom-right corner of your screen.
To
change the properties of a control, you must first select it by clicking it with the arrow
tool (from the Toolbox).
In the top dropdown list of the Properties window, you can see the name of the currently selected control, followed by its type.
| Remember that a Form is just another type of control. |
In the main list, you can see all the properties for the
selected control: each property has a unique name that identifies it. For
example, the text in the title bar of a form is set in the Caption property.
It is not important to learn all properties names/meanings now, instead remember that the
same property can be common to many controls. The most common property is Name
(always the first of the list), but we will see more of them later on.
To change a property value, just click on the property (note that a
description appears at the bottom) and type/select a value in the textbox directly beside
it.
Now, try creating controls and setting their properties and get familiar with them.
|
| Visual Basic Programming Zone is a website by
Lorenzo Dalla Vecchia. To contact the Webmaster, click here. Hosted by InWind: www.inwind.it |