The magazine of the Melbourne PC User Group

Visual Basic 4.0 (Professional Edition)
Tony Stephenson

Microsoft Visual Basic is now established as one of the most popular software environments for creating Windows applications. Using VB, you can create commercially viable applications, but the real advantage, from a programmer's point of view, is that it puts the fun back into programming.

16-bit or 32-bit applications?

This latest release, Version 4.0, is an integrated development environment for creating both 16-bit and 32-bit Windows applications. To run the faster 32-bit VB applications your computer must be configured with either Windows 95 or Windows NT (version 3.51 or later). The older style 16 bit VB applications will also run on those computers (see below for some restrictions), as well as on machines configured with Windows 3.1 or later. It is possible to create both 16-bit and 32-bit versions of the same application, using basically the same source code, by deploying conditional compilation. An example follows

#If Win32 then
' code specific to 32-bit
' systems is inserted here
#Else
' code specific to 16-bit
' systems is inserted here
#End If


The # (pound sign) differentiates these statements from the normal "If... Else ... End If" statement. "Win32" and its counterpart, "Win16", are VB predefined compiler constants.

You can choose to install the 16-bit and 32-bit versions of the Professional edition into the same directory or into separate directories. I chose the latter option because, having to support existing VB 3.0 (16-bit) applications, I wanted a delineation between the two versions.

Available documentation

A striking feature of this new edition of VB is the amount of documentation that comes with it. The Language Reference manual is over a 1000 pages, the Programmer's Guide is over 850 pages, and the Professional Features manual weighs in at nearly 550 pages. The CD-ROM contains "Visual Basic Books Online" which is installed if you install VB 4.0 from the CD-ROM (unfortunately this extra documentation is not available if you install from the floppy disks). Using Books Online means that all documentation is now conveniently stored in one location, allowing for quick electronic searching using keywords. It is accessed from the Help menu.

Flavours of VB

VB now comes in three editions - Standard, Professional, and Enterprise editions.

The Standard edition only comes in the 32-bit version, and contains the necessary controls for creating Windows applications. A control is a software object drawn on a window, and to which code is attached. An example of a control is a button which, when clicked using a mouse, carries out some action (the action is defined by the attached code).

The Professional edition contains more controls than the standard edition, as well as extra software, such as "Crystal Report Writer". CRW is used to generate reports, lists, letters, labels, and so on, using data from existing databases. It has inbuilt functionality to perform calculations, compare values, format data, do logical testing (using the operators "and", "or", and "not"), and to incorporate freeform text.

The Enterprise edition has been designed for creating client/server applications suitable for running in an enterprise environment. It contains extra features such as the "Component Manager", the version control system "Visual SourceSafe", Remote Data Objects (RDO) and the RemoteData control (RDC).

The Component Manager is a tool for managing OLE objects and OLE servers (in Microsoft terminology, an OLE server "is an application that provides objects to other applications").

Visual SourceSafe is a source code management system suitable for team development environments.

Remote Data Objects (RDO) is a programming interface using OLE-based data access objects which can be used to access a remote database. The RemoteData control is similar in behaviour to the Jet "Data" control.

The Enterprise edition contains everything in the Professional edition plus a lot more. The Professional and Standard editions have a similar relationship.

What's new in VB 4.0

VB 4.0 has a new language engine - VBA (Visual Basic for Applications). This engine is not only backward compatible with previous versions of VB, but also with the versions that come with Microsoft Excel 5 and Project 4. One advantage with this new engine, which might seem trivial to anyone but a programmer, is the inclusion of a line continuation character (a space followed by an underscore). The ability to split a logical line over two or more physical lines means greater source code readability and easier debugging.

The main advantage of the new engine is that it allows for easier creation of applications that support OLE Automation than was previously possible.

But what is OLE automation?

Visual Basic 4.0 is now a development environment strongly based around the concept of objects, as are an increasing number of other Microsoft products. However, by some definitions, VB is still not be regarded as a true object-oriented programming language (whatever that is!). So within a spreadsheet, worksheets or cells can be regarded as objects. Similarly, within a wordprocessor, sentences, paragraphs, and so on are objects. It is possible from within a VB application to control and access these objects. For example, you could, from within your VB application, use a wordprocessing object to create and display a table. So, according to the Programmer's Guide, by "using OLE Automation, you can 'borrow' the functionality of another application by controlling its objects from within your VB application."

To find out information about objects, VB now includes an "Object Browser." So, for example, you use the Browser to examine the contents of object libraries, which contain information about objects such as their methods and properties.

Controls, controls, and yet more controls

There are lots of new controls in VB 4.0, plus extra properties for those controls that were previously available with version 3.0. Properties are characteristics that uniquely define a control, and which can be set either when designing a VB application or when it is running. An example of a property for a command button is its caption.

What are some of these new controls?

One that immediately stands out is the "SSTab" control, a group of tabs, which diagrammatically looks like the tabs that appear on folders hanging in a filing cabinet. The power of this control is that each tab is a container for other controls, that is, other controls, such as command buttons, text boxes, radio buttons and so forth can be associated with a particular tab. The SSTab control allows an application's functionality to be both logically split up and represented in a visually appealing manner.


Figure 1 Visual Basic SSTab control


Figure 2. Visual Basic Object Browser

Another interesting control that can be used in imaginative ways is the "RichTextBox" control. Similar to the conventional "TextBox" control in that you use it to allow users to enter and edit text, this new control offers a lot more flexibility when it comes to formatting that text. The most welcome feature of this control is that it is possible to format any section of the entire text in the following ways. Make the text bold or italic; change its colour; create superscripts or subscripts; set the margin settings for paragraphs; and so on. (Note however that this control is an example of a 32-bit custom control that can only run on 32-bit systems such as Windows 95 and Windows NT 3.51 or higher).

There are other controls

  • To track the progress of a time-consuming task (the "ProgressBar" control)
  • To select a value using a "slider" control, which is similar in appearance to a sliding volume control found on hi-fi equipment
  • To see a hierarchical representation of information in a tree-like format, similar to the graphical representation used by the "old" Windows File Manager (the "TreeView" control)
  • To display items a new way, using one of four different views (the "ListView" control)
  • And so on.
T here is also another type of control known as "insertable objects". Examples of this type of control are Microsoft Excel Worksheet objects or Microsoft Project Calendar objects. An insertable object is regarded as a "custom control" because it can be added to the toolbox.

The documentation for these controls can be found in either the online help or in the hardcopy "Custom Control Reference" which is a subsection of the "Professional Features" manual. All of the relevant properties, events, functions, and methods are fully explained using cross-references and examples where necessary.

Tool tips (little boxes which contain a description of an object when the mouse cursor is positioned over that object) have now been incorporated into VB. Although only a relatively minor feature, it does mean that it is no longer necessary to remember what each of the icons in the toolbox represents.

Adding and deleting custom controls

Clicking on the "Custom Controls" option of the main design menu option "Tools" displays a list box containing the names of the custom controls, each with an associated check box. If the checkbox contains an "x", then this particular control's icon appears in the toolbox.

To add a custom control to the toolbox, simply click on the checkbox of the desired control and click "OK". The reverse procedure of clearing a a checkbox of its "x" will remove the control from the toolbox [if this control is still being used, you will be prevented from removing it].

What about VBXs?

VBXs (shorthand for Visual Basic custom controls) are now only supported in VB 3.0 and the 16-bit version of VB 4.0. OLE custom controls (known as OCXs) are the new control model used in VB 4.0 (this architecture combines the advantages of VBXs with OLE). VB 4.0 contains OCXs that are upgrades to the VBXs supplied with earlier versions of VB. However if your existing applications (versions of VB 3.0 or earlier) are using custom controls from third-party suppliers, you must wait until these suppliers have released OCX versions before you can upgrade your applications to run in VB 4.0's 32-bit environment.

New Structure for Project Files

The MAK project file of previous versions has been replaced with the VBP project file. The VBP file contains
  • A .FRM file for each form;
  • A .FRX file for any form containing controls which have properties set to binary data values;
  • A .CLS file for each class module. In VB terminology, a class is a formal definition (a "blueprint") of an object, and class modules are used to create your own objects by defining classes of objects;
  • A .BAS file for each standard code module;
  • .VBX and .OCX files containing custom controls;
  • A single .RES resource file, which can contain bitmaps, text strings, and so on. The advantage of a resource file is that you can change its contents without having to re-edit the actual code in your application.
Jet engine

VB 4.0 contains two versions of the Microsoft Jet (Access) database engine--Jet Version 3.0 for 32-bit development and Jet Version 2.5 for 16-bit development.

Any commercial developer is strongly encouraged to read the help topic "Obsolete Features in DAO" (Data Access Object) to review features that have been replaced in the Jet 3.0 version.

Add-Ins

VB 4.0 can be extended through the use of Add-Ins (available as a new main menu option on the VB design menu). An Add-In is an OLE server, which can be added or removed using the Add-In Manager. Add-Ins can be purchased from third-party suppliers or created yourself using VB. The Spy sample program that ships with VB 4.0 demonstrates the necessary steps for creating your own Add-In.

After migrating to VB 4.0

After you have installed VB 4.0 and are looking to familiarise yourself with the differences between this and previous versions, read the document "Questions and Answers About Microsoft Visual Basic for Windows Version 4.0 (ReadMe)." You can locate this document by searching VB 4.0's online help using the keywords "questions and answers." When you display this topic, you will also see another topic underneath it simply called "Text Files." This includes the names of eight text files, each of which contains additional information about VB 4.0.

Visual Basic 4.0 is a functionally rich and visually appealing environment for developing industrial-strength information systems. However, version 4.0 is a major step-up from version 3.0 which itself was no software lightweight. So be prepared to spend some considerable time in learning the features of this product, especially OLE (OLE servers and OLE automation), and to gain an understanding of Data Access Objects.

Requirements for VB 4.0

386 processor or higher.
50 MB of free hard disk space for a full installation.
Floppy diskette drive or CD-ROM drive. 8 MB RAM if running
Windows 95.

Seeing the Basics in 1996

The structure of the column is changing this year. Rather than being a monthly collection of unrelated hints or tips about VB, each month will now concentrate on a specific topic of VB.

Next month, the topic will be Creating your first VB 4.0 project, (differences between the process for this new version and VB 3.0 will be highlighted).

Reprinted from the February 1996 issue of PC Update, the magazine of Melbourne PC User Group, Australia
 

[About Melbourne PC User Group]