VISUAL BASIC_6
 

Creating an Application or a Project:


Functionalities required for the different Controls:

Let us  assume that on clicking the first button, a message box  should be displayed.   On clicking the second button a rectangle filled with yellow color should appear.   On clicking the third button a welcome message should appear in the text box.   On clicking the fourth button the welcome message should be erased.  

Writing Codes for the Controls:

The code window is opened by double clicking the concerned control.   The header line and the ending line of the relevant function will automatically appear on the code window.   You have to enter only the body for the function.   For referring to a property, the usual dot notation used in OOP is used.   For example the Text property of a text box named Text1 is referred to as Text1.Text.   In a similar fashion methods can also be referenced.  The codes for all the controls will  be on the same window  and the final  code window will  look as shown in the figure 3a.

Private Sub Command1_Click()

'display message box

MsgBox ("this is a sample message")

End Sub

 

Private Sub Command2_Click()

ScaleMode = 3

Line (100, 10)-(300, 150), RGB(255, 255, 0), BF

End Sub

 

Private Sub Command3_Click()

Text1.Text = "welcome to VB6"

End Sub

 

Private Sub Command4_Click()

Text1.Text = ""

End Sub

 

Private Sub Command5_Click()

End

End Sub

 

Saving the Project:

 When a project is saved for the first time it is done in two steps.  When you select ‘Save Project as’ from the File menu, you will get the first dialog box which asks you to save the form file with .frm extension.   On saving the form file another dialog box appears asking you to save the Project file itself.   We can give appropriate names to the form and the project, but in this case we retain the default names form1 and project1.   The project is now saved as project1.vbp and the form file is stored as form1.frm.   When you want to save the project after any subsequent editing, it is enough if you click ‘Save Project’.  Both the form and the project are saved by this single Save command.

Running the Project:

For running the project click Run->Start.   The output window appears with all the controls.   This  window represents the Run mode.   Click the buttons one by one and check the outputs obtained.  A typical output is shown in the figure 4.

Closing  and Reopening the Project:

For Closing the project click on the  closing button of the output window or click  End from the Run menu or the exit button in the output window.   If you want to reopen the project, click ‘open project’ from the File menu.   Opening a project will open all the files in the project.

Viewing the Project Explorer Window:

As we said earlier, when you develop an application, you work with a project to manage all the different files that make up the application.   In order to view the constituents of the project, open the project explorer window by selecting the item ‘Project Explorer’ from the View Menu.   The Project Explorer window for the above application is also shown in the figure 3.   This project uses only two files, one project file(project1.vbp ) and one form file(form1.frm).   But in  general a Project may consist of the following files.

  1. One Project File that keeps track of all the components(.vbp).

  2. One file for each form(.frm).

  3. One binary data file for each form containing data for properties of controls on the form(.frx). These files are not editable and are automatically generated for any .frm file that contains binary properties, such as Picture or Icon.

  4. Optionally, one file for each class module(.cls).

  5. Optionally, one file for each standard module(.bas).

  6. Optionally, one or more files containing ActiveX controls(.ocx).

  7. Optionally a single resource file(.res).

Thus a project file is simply a list of all the files and objects associated with the project, as well as information on the environment options you set.   This information is updated every time you save the project.  All of the files and objects can be shared by other projects as well.


Figure 4

Creating an EXE File:

After completing all the files for a project, you can convert the project into an executable file(.exe) by selecting ‘the make project.exe’ command from the file menu.    An EXE file can be executed outside VB environment and so can be freely distributed.

Summary:

In this lesson we have seen some features of the Visual Basic Integrated Development Environment, and how to create an application, using the three elements, form, controls and codes.  It may be noted that any complex application will consist of only these three elements, possibly using more forms, more controls with complex functionalities (pre-defined as well as user defined) and some complex logic involving the properties of the controls. 


 

Copyright © 2001 Selfonline-Education. All rights reserved.