Day 6: Creating a Visual Basic Application from the Prototype

The above prototype is a Microsoft Access application. We could polish it and release it as a Microsoft Access application or port it to another language. One fast solution is to convert the application to a Visual Basic multiple-document-interface (MDI) application. Before looking at this solution, let us look at some languages.

Which Product Should We Use?

Writing Windows-based applications means selecting one or more application languages. In a business environment, success means delivering quality products on time at an acceptable cost. An application can be written many ways. Selecting a language requires a consideration of trade-offs among its properties.

These tables show my own opinion of some common languages and their characteristics.

Development Properties of Common Languages

Property

Assembly

C++

Visual Basic

Microsoft Access

Training time

Very high

High

Low

Very low

Speed

Very high

High

Medium

Medium

Report ability

None

Low

Medium

High

Contractor availability

Low

Medium

High

High

Development time

Very high

High

Medium

Low

GUI control

Very high

High (VBX, DLL)

High (VBX)

Low (OCX)


User Properties of Common Languages

Property

Assembly

C++

Visual Basic

Microsoft Access

Ad hoc reports

No

No

No

Yes

RAM needs

Low

Medium

Medium (2-4 MB)

High (8-12 MB)

Disk space

Low

Medium

Medium

Medium

Processor

80386/16

80386/16

80386/25

80486


Microsoft Access to Visual Basic

Converting a Microsoft application to a Visual Basic application is a simple process. This process may be done by hand or by using a utility. I will show you a utility I roughed out in a few days that points the way to building a complete utility.

Before going into the process, we should take a peak at the result of the conversion to a Visual Basic application.

To get this Visual Basic application, I simply pressed the Create VB Application button and then opened the Visual Basic .MAK file generated. I do not even need to know how to code Visual Basic to create this application.

We will examine how this conversion occurs because you will want to enhance or modify it.

The stages of conversion are simple:

  1. Use a the documentation Wizard to create an Object Definition table that contains all of the information about the application.
  2. Use this information to generate the Visual Basic code.

This is not a talk about compiler construction, so I will give only a few highlights.

The first step is put everything you wanted to know about the application into a single table. Most of the code is already written for you when you install Microsoft Access.


On Error Resume Next
        DoCmd RunSQL "Drop Table [Object Definition];"
        On Error GoTo 0
        DoEvents
        MsgBox "We are going to run the DATABASE DOCUMENTOR next. Select [ALL Objects Types] and [Select All], then unselect VB207 items.", 64, "Capturing Data"
        rc% = Doc_PrintDataBase() 'Document Database
        SendKeys "%FT", True
        SendKeys "%FC", True
        rc% = VB207_A2VB()

Delete any existing table with the name Object Definition and then tell the user what to select. The code now calls the Document Database function, which displays the Database Documentor dialog box for selecting objects.

After selecting the items, we click the OK button. When this routine is completed, I use the Sendkeys command to save the report that was generated as a table. We then close the Print Preview window, which was automatically opened.

The data in this table is very well organized and contains all the information that is needed.

The data is arranged in a hierarchy or tree with the components related by ID and ParentID. The Name field indicates the properties and the other fields indicate the actual value.

To illustrate how we can extract data, consider the following records:

ID

ParentID

Object Type

Name

Extra1

12280

0

Module

VB207 Forms and Reports

""""""

12282

12280

Property

Date Created:

1/25/95 11:21:14 AM

12284

12280

Code

1

Option Compare Database 'Use database order for string comparisons

12285

12280

Code

2

Type tagVB207Action

12286

12280

Code

3

Action As Integer

12287

12280

Code

4

DBType As String

12288

12280

Code

5

ODBCConn As String

12289

12280

Code

6

End Type

12290

12280

Code

7

Global VB207Action As tagVB207Action

12291

12280

Code

8

"Declare Function TimeGetTime Lib ""MMSYSTEM"" () As Long"


These records show how the various lines of a module are stored in the table. To reassemble the module, we simply find the ID of the parent (whose Object Type is Module) and then select all the Code records with this parent.

This type of structure occurs throughout this table. A form's ID can be used to find its code and controls. Each control's ID can be used to find the properties of the control.

At the highest level, we can convert all the forms by code as simple as:


Set DB = DBEngine(0)(0)
Set RS = DB.OpenRecordset("Select * from [Object Definition] Where [Object Type]='Form';")
DoCmd Hourglass True
While Not RS.eof
    Create_Form RS("ID"), RS("Name")
    RS.MoveNext
Wend

The function Create_Form takes us down to the next level. Its code looks like this:


Set DB = DBEngine(0)(0)
Set RS = DB.OpenRecordset("Select * from [Object Definition] Where [ParentID]=" + Str$(ID&) + ";")
While Not RS.eof
    
    Select Case RS("Object Type")
    Case "Code"
        Project.form.Code = Project.form.Code + RS("Extra1") + CR$
    Case "Control"
         AddControl RS("ID"), RS("Name"), RS("Extra1")
    Case "Property"
        FormProperty RS("Name"), RS("Extra1")
    Case "Section"
          AddSection RS("ID"), RS("Name")
    Case "User Permissions"
    Case "Group Permissions"
End Select
    RS.MoveNext
Wend

This process continues until we exhaust the tree.

The sample converter shows the mechanics of this process and may be used to build one that corresponds to your firm's standards and GUI requirements.