Microsoft VB6 Tutorials
Microsoft VB6 Tutorials
Visual Basic
Tutorials
Lesson1 : Introduction to Visual Basic 6
1.1 The concept of computer
programming
Before we begin Visual Basic 6 programming, let us understand some basic
concepts of programming. According to Webopedia, a computer program is
an organized list of instructions that, when executed, causes the computer
to behave in a predetermined manner. Without programs, computers are
useless. Therefore, programming means designing or creating a set of
instructions to ask the computer to carry out certain jobs which normally
are very much faster than human beings can do.
A lot of people think that computer CPU is a very intelligent thing, which in
actual fact it is a dumb and inanimate object that can do nothing without
human assistance. The microchips of a CPU can only understand two
distinct electrical states, namely, the on and off states, or 0 and 1 codes in
the binary system. So, the CPU only understands a combinations of 0 and 1
codes, a language which we called machine language. Machine language is
extremely difficult to learn and it is not for us laymen to master it easily.
Fortunately , we have many smart programmers who wrote interpreters and
compilers that can translate human language-like programs such as BASIC
into machine language so that the computer can carry out the instructions
entered by the users. Machine language is known as the primitive language
while Interpreters and compilers like Visual Basic are called high-level
language. Some of the high level computer languages beside Visual Basic
are Fortran, Cobol, Java, C, C++, Turbo Pascal, and etc .
On the other hand, because the user may click on a certain object
randomly, so each object has to be programmed independently to be able to
response to those actions (events). Therefore, a VB Program is made up of
many subprograms, each has its own program code, and each can be
executed independently and at the same time each can be linked together in
one way or another.
In this section, we will not go into the technical aspects of Visual Basic
programming yet, what you need to do is just try out the examples below to
see how does in VB program look like:
Example 2.1.1 is a simple program. First of all, you have to launch Microsoft
Visual Basic 6. Normally, a default form with the name Form1 will be
available for you to start your new project. Now, double click on Form1, the
source code window for Form1 as shown in figure 2.1 will appear. The top of
the source code window consists of a list of objects and their associated
events or procedures. In figure 2.1, the object displayed is Form and the
associated procedure is Load.
When you click on the object box, the drop-down list will display a list of
objects you have inserted into your form as shown in figure 2.2. Here, you
can see a form with the name Form1, a command button with the name
Command1, a Label with the name Label1 and a Picture Box with the name
Picture1. Similarly, when you click on the procedure box, a list of
procedures associated with the object will be displayed as shown in figure
2.3. Some of the procedures associated with the object Form1 are Activate,
Click, DblClick (which means Double-Click) , DragDrop, keyPress and more.
Each object has its own set of procedures. You can always select an object
and write codes for any of its procedure in order to perform certain tasks.
You do not have to worry about the beginning and the end statements (i.e.
Private Sub Form_Load.......End Sub.); Just key in the lines in between the
above two statements exactly as are shown here. When you press F5 to run
the program, you will be surprise that nothing shown up .In order to display
the output of the program, you have to add the Form1.show statement like
in Example 2.1.1 or you can just use Form_Activate ( ) event procedure as
shown in example 2.1.2. The command Print does not mean printing using a
printer but it means displaying the output on the computer screen. Now,
press F5 or click on the run button to run the program and you will get the
output as shown in figure 2.4.
Example 2.1.1
Form1.show
End Sub
Example 2.1.2
Print 20 + 10
Print 20 - 10
Print 20 * 10
Print 20 / 10
End Sub
You can also use the + or the & operator to join two or more texts (string)
together like in example 2.1.4 (a) and (b)
Example 2.1.4(a)
Example 2.1.4(b)
Private Sub
Private Sub
A = Tom
A = Tom
B = “likes"
B = “likes"
C = “to"
C = “to"
D = “eat"
D = “eat"
E = “burger"
E = “burger"
Print A & B & C & D & E
Print A + B + C + D + E
End Sub
End Sub