Networking with Internet (Visual Basic)

Visual Basic 6.0

Home | About Me | Pieces Of Mhe | Circle of Friends | Visual Basic History | Visual Basic 6.0 | Visual BAsic Working with Controls | Visual Basic Working with Functions | Visual Basic Working with Functions2

Learning Visual Basic
Part 2: The Visual Basic Programming Environment
"Programming is not magic and you can do it."
 

     As the previous flowchart showed, you have to have the Basic software before you can complete a working program. The good news is that Microsoft does provide a first class development environment called Visual Basic Express. (You can read all about it in my complete tutorial - click here.) The bad news is that we're not going to base this tutorial on Microsoft's free system. We're going to assume that you're using Visual Basic version 6.0. More bad news is that it's becoming very difficult to actually buy a new copy of VB 6. Microsoft is doing a pretty good job of exterminating it in the retail market because you simply can't buy it from them anymore. The only copies that are available are left over from years ago. In fact, Microsoft stopped supporting it as a 'Mainstream' product in 2005.

The reason we're using VB 6.0 is first, to provide a really great VB environment. (Although Microsoft doesn't support it anymore, we do here and it is pretty great.) And second, to provide a tutorial that will match the software that a lot of people still actually use, in spite of Microsoft's position on it.

For the rest of you, make sure you have VB 6 installed and then start it up! You should see a development environment that looks something like this:  

               

Notice that in the previous flowchart, the arrows pointed both ways from the computer to the 'operating system' and 'software libraries'. That is because you can actually make your own software modifications using VB. That's what some of the other icons are for. But for now, click the default "Standard EXE" icon and then click the "Open" button.

You should now see something that looks like this:

                   

There are a lot of display options at this point and you might see other parts of Visual Basic on your computer such as the 'Project Explorer' window ...

                                    

... the 'Toolbox' ... 

                                 

... or several other things. This leads to the next point. Your VB development environment has a lot of different components and you don't have to know what they all are right away. We're going to keep things as simple as possible and avoid discussing anything that you don't absolutely need. As you gain skill in VB, you'll figure out the new stuff.

 

KControls

KControls are ActiveX controls written in Visual Basic 6.

 


KTab Control

26 KB

  • Right to left alignment. 
  • Transparent. 
  • Picture property with different styles. 
  • Placing controls in tabs at design time.
  • Align property.

KText Control

13 KB

  • Input mask for date and time data type.
  • Suppress input for different data types.
  • Data aware control.
  • Suppress maximum and minimum values.
  • Support RightToLeft.
  • Built in list with different properties.
  • Built in calendar.
  • Built in calculator.
  • Kashida and space controlling. 
  • Flat style appearance.

KButton Control

13 KB

  • Flat style
  • Controlled caption alignment.
  • Controlled picture alignment.
  • Pictures for different sates.
  • Align property.
     

KFrame Control

16 KB

  • Enhanced appearance.
  • Align property.

 

 KContainer Control

18 KB

  • Scrollable host control.
  • RightToLeft support.
  • Picture property.
  • Align property.

KPanel Control

14 KB

  • For hosting controls
  • Align property.
  • Align property.


KLabel Control

9 KB

  • Transparent Label control.
  • 3D property.
  • Data aware.
  • Convert value to string


KRTFPrint Control

29 KB

  • Margins.
  • Header and footer.
  • Page count.
  • Print by page number.
  • Print to printer or screen.
  • Preview example included.

Creating Your First Application

 In this section, we are not going into the technical aspects of VB programming; just have a feel of it. Now, you can try out the examples below:

Example 2.1.1 is a simple program. First of all, you have to launch Microsoft Visual Basic. Normally, a default form 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, command button with the name Command1, a Label with the name Label1 and a PictureBox 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 Form are Activate, Click, DblClick (which means Double-Click) , DragDrop, keyPress and etc. 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 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.

 You can also perform simple 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.1 Source Code Window

 

 

Figure 2.2: List of Objects

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Figure 2.2: 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
B = “likes"
C = “to"
D = “eat"
E = “burger"
Print A + B + C + D + E

Example 2.1.4(b)

Private Sub
A = Tom
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.

2.2 Steps in Building a Visual Basic Application

 

Generally, there are three basic steps in building a VB application. The steps are as follows:

Step 1 : Design the interface
Step 2 : Set Properties of the controls (Objects)
Step 3 : Write the events' procedures

 

Enter supporting content here