2.1 Creating Your First Application
In this lesson, we will not delve into
the technical aspects of Visual Basic programming yet, we just want you to try out the examples below
to see how does a Visual Basic program behave.
First of all, launch Microsoft Visual Basic 6
compiler that you have installed earlier. In the New Project Dailog ,
choose Standard EXE to enter
Visual Basic 6 integrated development environment. In the VB6 IDE, a
default form with the name Form1 will be presented to you. Now,
double click on Form1 to bring up the source code window for Form1 as shown in Figure 2.1
. The top of the source code window consists of a list of objects and
their associated events or procedures. In the source code window, the object displayed is
Form1 and the associated procedure is Load.
Figure 2.1 Source Code Window
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 can also perform arithmetic calculations as shown in Example 2.1.2. VB uses * to denote the multiplication operator and / to denote the division operator. The output is shown in Figure 2.5, where the results are arranged vertically.
Figure 2.2: List of Objects
Figure 2.3: List of Procedures
Example 2.1.1
Private Sub Form_Load ( )Form1.show
Print “Welcome to Visual Basic tutorial”
End Sub
Figure 2.4 : The output of Example 2.1.1
Example 2.1.2
Private Sub Form_Activate ( )Print 20 + 10
Print 20 - 10
Print 20 * 10
Print 20 / 10
End Sub
Figure 2.5: The output of Example 2.1.2
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)
Private Sub
A = "Tom"End Sub
B = “likes"
C = “to"
D = “eat"
E = “burger"
Print A + B + C + D + E
Example 2.1.4(b)
Private Sub
A = "Tom"End Sub
B = “likes"
C = “to"
D = “eat"
E = “burger"
Print A & B & C & D & E
The Output of Example 2.1.4(a) &(b) is as shown in Figure 2.7.
Figure 2.7
2.2 Steps in Building a Visual Basic Application
Step 1 : Design the interface by adding controls to the form and set their propertiesStep 2 : Write code for the event procedures
0 comments:
Post a Comment