Saturday, September 7, 2024

Visual Basic Project Files Structure

Microsoft VB has been a popular and powerful development environment for the Windows Platform. It has emerged since VB 1 for MS DOS and now the robust VB 6 and VB.NET is in action. The Basic unit for the VB programs is the Project.

The project has a number of units which are forms, MDI forms, Standard Modules, Class Modules, User defined ActiveX controls, Property Pages for these controls and ActiveX designers such as Data Report, WebClasses, DataEnvironment, DHTML Pages, UserConnections, Resource files and other related files.

These files look pretty in VB development environment, but very limited people know that these are the simple ASCII text files. Such files can be produced by a simple text editor such as notepad. These files have a simple structure that is very easy to understand. These files are discussed in a little detail below.

Project Files
Look at the following lines. These lines completely describe the contents of the Standard EXE project.

Type=Exe
Form=Form1.frm
Reference=*G{00020430-0000-0000-C000-000000000046}
#2.0#0#….SYSTEMstdole2.tlb#OLE Automation
Module=Module1; Module1.bas
UserControl=UserControl1.ctl
Class=Class1; Class1.cls
Startup=”Form1″
Command32=””
Name=”Project1″
HelpContextID=”0″
CompatibleMode=”0″
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1

The first line, Type describes the type of the project. It is EXE for Standard EXEs, oleEXE for ActiveX EXEs, oleDLL for ActiveX DLLs, CONTROL for ActiveX control. The other line gives the first form file. The reference line gives the reference to the file added from the references dialog box. It specifies the GUID and filenames for the components. The next lines give the project components and their filenames. For instance, the project has a standard module, a usercontrol, a class and the startup object is form1. The next lines set the options in the project properties dialog box, which are the project name, HelpContextID, The Compatibility options, Version number options, the state of Remote server Files option, the compilation type (in this instance, Native code), the optimization type (Optimize for fast code here), The value for Favour Pentium Pro and Create symbolic debug info checkboxes. The next six lines set the value for advanced optimization options.

The Next line sets the Startup Mode for ActiveX components. It is always 0 for standard EXE Projects. The Next 4 lines return to the General tab and set the values for Unattended Execution, Retained in memory options and the Threading options for ActiveX components.

Form Files
The form file contains the necessary references to controls and the code contained in the form. Look at the following text of a typical form file with a command button, a textbox and some code.

VERSION 5.00
Begin VB.Form Form1
    Caption = “Form1”
    ClientHeight = 3195
    ClientLeft = 60
    ClientTop = 345
    ClientWidth = 4680
    LinkTopic = “Form1”
    ScaleHeight = 3195
    ScaleWidth = 4680
    StartUpPosition = 3 ‘Windows Default
    Begin VB.CommandButton Command1
        Caption = “Command1”
        Height = 495
        Left = 1800
        TabIndex = 1
        Top = 1320
        Width = 1215
    End
    Begin VB.TextBox Text1
        Height = 495
        Left = 360
        TabIndex = 0
        Text = “Text1”
        Top = 240
        Width = 1215
    End
End

Attribute VB_Name = “Form1”
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub Command1_Click()
    Text1.Text = “Hello World”
End Sub
Private Sub Form_Load()
    Text1.BackColor = vbBlue
End Sub

The first line describes the form module version. The next line marks the start of the form named form1. The next lines up to startup position set the properties of the form. Caption, Height, Left, Top, Width, LinkTopic, ScaleHeight, ScaleWidth, and StartUp Position.

The next line marks the Start of CommandButton, Command1. The next lines set the familiar properties of the command button. The same is with the lines specifying the textbox. Finally the form definition is ended and some advanced properties are set and finally the code is listed as it is.

Module Files
The Module files are a simple listing of the code with only a simple property, the Name. Below is a simple Module file, with an empty sub main.

Attribute VB_Name = “Module1”
Sub main()
End Sub

User Control Files
The usercontrols are the ActiveX controls created by the developers. Their file format is very similar to the form file. Below is a simple Empty usercontrol file.

VERSION 5.00
Begin VB.UserControl UserControl1
    ClientHeight = 3600
    ClientLeft = 0
    ClientTop = 0
    ClientWidth = 4800
    ScaleHeight = 3600
    ScaleWidth = 4800
End
Attribute VB_Name = “UserControl1”
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False

Class Files
VERSION 1.0 CLASS
BEGIN
    MultiUse = -1 ‘True
    Persistable = 0 ‘NotPersistable
    DataBindingBehavior = 0 ‘vbNone
    DataSourceBehavior = 0 ‘vbNone
    MTSTransactionMode = 0 ‘NotAnMTSObject
END

Attribute VB_Name = “Class1”
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Public Property Get msg() As Variant
End Property
Public Property Let msg(ByVal vNewValue As Variant)
End Property

It is a simple class with just 1 property, msg. The properties of the class are contained between the BEGIN and END block. The rest apply only to ActiveX servers. They are just the instancing and persisting properties.

UserDocument Files
VERSION 5.00
Begin VB.UserDocument UserDocument1
    ClientHeight = 3600
    ClientLeft = 0
    ClientTop = 0
    ClientWidth = 4800
    HScrollSmallChange= 225
    ScaleHeight = 3600
    ScaleWidth = 4800
    VScrollSmallChange= 225
End
Attribute VB_Name = “UserDocument1”
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

This is very similar to the Usercontrol and the Class file. The userdocuments are used to create applications for the web.

MC MCSE is a popular computer certification website devoted to providing free learning materials to candidates pursuing Microsoft, CompTIA and Cisco certifications. To access these resources visit http://www.mcmcse.com

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles