2.1 Creating Your First Application
In this lesson, we will not delve into the technical aspects of Visual Basic programming yet, what you need to do is to try out the examples below to see how does a Visual Basic program looks 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.
Figure 2.1 Source Code Window
|
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 surprised 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.
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.3, where the results are arranged vertically.
Figure 2.2: List of Objects | Figure 2.3: List of Procedures |
Example 2.1.1Private 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.2Private 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 |
| End Sub |
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 properties
Step 2 : Write code for the event procedures
No comments:
Post a Comment