Sample Applications Contents
Visual Basic 4.0 Samples Help

Samples Notes for Microsoft® Visual Basic® Professional Edition Version 4.0 ©, Copyright Microsoft Corporation, 1995

Standard Edition

First App (BUTTERF.VBP, PICVIEW.VBP)

Alarm Clock (ALARM.VBP)

CallDlls (CALLDLLS.VBP)

Controls (CONTROLS.VBP, CALC.VBP)

Datactrl (BIBLIO.VBP)

Dynamic Data Exchange (DDE.VBP)

FileCtls (WINSEEK.VBP)

FileIO (RECEDIT.VBP)

Graphics (BLANKER.VBP)

ListCombo (LISTCOMBO.VBP)

Loan Calculator (LOAN.VBP)

MDI Notepad (MDINOTE.VBP)

Menus (TEXTEDIT.VBP)

Mouse (MOUSE.VBP)

OLE Container (OLECONT.VBP)

Resource (ATM.VBP)

Professional Edition

Add-ins (SPY.VBP, ALIGN.VBP)

Communications (VBTERM.VBP, DIALER.VBP)

Crystal Reports (CROCXSAM.VBP)

Data Access (VISDATA.VBP)

Data Form Designer (DFD.VBP)

MAPI (VBMAIL.VBP)

Multimedia MCI (MCITEST.VBP)

OLE Automation (DS.VBP, THINGTST.VBP, LOGINDLG.VBP, DLGTEST.VBP, LOGINDLG.XLS, GRAVITY.VBP, GRAVTEST.VBP)

Outline (PHONE.VBP)

Picture Clip (REDTOP.VBP)

Enterprise Edition Sample Applications

Booksale (BOOK_CLI.VBP and BOOK_SVR.VBP)

Callback (CLBK_CLI.VBP and CLBK_SVR.VBP)

Hello World (HELO_CLI.VBP and HELO_SVR.VBP)

Interface (INTR_CLI.VBP and INTR_SVR.VBP)

Jet/DAO (JET1_CLI.VBP and JET1_SVR.VBP)

ODBC (ODBC_CLI.VBP and ODBC_SVR.VBP)

Passthrough Server (PASS_CLI.VBP and PASS_SVR.VBP)

Pool Manager (PMGR_CLI.VBP and PMGR_SVR.VBP)

Remote Data Objects (RDO) (RDO_CLI.VBP and RDO_SVR.VBP)

Note   Some of the sample applications use conditional compilation to make calls to 16-bit and 32-bit APIs.  If you are using the 16-bit version of Visual Basic in a 32-bit operating environment, the sample applications will still make calls to 16-bit APIs.


FirstApp (BUTTERF.VBP, PICVIEW.VBP)

Butterfly Sample

The sample program demonstrates using the Move method to make a butterfly "fly" across the screen.  For more information, see Chapter 2, "Your First Visual Basic Application," in the Programmer's Guide.

Background

The Butterfly application demonstrates how an image control can be used to create a simple animated butterfly.  The application consists of three image controls.  The first image control is loaded with an "open" butterfly bitmap and the second with a "closed" butterfly bitmap (see Figure 2.6).  When the third image control is loaded first with the "open" bitmap and then with the "closed" bitmap, the butterfly appears to open and close its wings while moving across the screen.

File	Description

BFLY1.BMP	Bitmap of a butterfly with open wings.

BFLY2.BMP	Bitmap of a butterfly with closed wings.

BUTTERF.FRM	The main form for displaying the butterfly.

BUTTERF.FRX	Binary file for holding resources for the BUTTERF.FRM file.

BUTTERF.VBP	The project file for this sample application.

To Run

From the Visual Basic File menu, choose Open Project and select the BUTTEF.VBP file, which is listed in the \SAMPLES\FIRSTAPP subdirectory of the main Visual Basic directory.  Press F5 or choose Start from the Run menu to run the application.

Picview Sample

This sample program is a simple yet useful application that allows you to view bitmaps, icons, or Windows metafiles.  For more information, see Chapter 2, "Your First Visual Basic Application," in the Programmers Guide.

Background

The application consists of six controls: a drive list box, a directory list box, an image control, a file list box, a label, and a command button.  When you run the application, you can display a picture by double-clicking the filename of a bitmap, icon, or metafile in the file list box.

File	Description

PICVIEW.FRM	The main form for the sample.

PICVIEW.VBP	The project file for this sample application.

To Run

From the Visual Basic File menu, choose Open Project and select the PICVIEW.VBP file, which is listed in the \SAMPLES\FIRSTAPP subdirectory of the main Visual Basic directory.  Press F5 or choose Start from the Run menu to run the application.


Controls Sample Application
Controls (CONTROLS.VBP, CALC.VBP)

Controls Sample

This sample program features Visual Basic controls such as the TextBox, Scrollbar, CommandButton, and others.  The sample also shows the usage of standard properties such as the Caption property.

Background

The sample is comprised of several forms, each with a control or set of controls on it.  Controls demonstrated include the following: TextBox, HScrollbar, ListBox, PictureBox, OptionButton, CommandButton and Label control.  For more information, see Chapter 3, "Creating and Using Controls," in the Programmer's Guide.

File	Description

ARRAY.FRM	Form demonstrating usage of a control array.

BUTTON.FRM	Form demonstrating the usage of CommandButton controls.

BUTTON.FRX	Binary data file for the BUTTON.FRM file.

CHECK.FRM	Form demonstrating usage of a CheckButton control.

CONTROLS.VBP	The project file for the sample application.

LISTBOX.FRM	Form demonstrating usage of the ListBox control.

MAIN.FRM	The main form for the sample application.

MULTI.FRM	Form demonstrating usage of the ListBox control.

NUMBER.FRM	Form demonstrating usage of OptionButton controls.

SCROLL.FRM	Form demonstrating usage of Scrollbar controls.

WORDWRAP.FRM	Form demonstrating usage of CheckBox controls with a Label control.

To Run

From the Visual Basic File menu, choose Open Project and select the CONTROLS.VBP file, which is listed in the \SAMPLES\CONTROLS subdirectory of the main Visual Basic directory.  Press F5 or choose Start from the Run menu to run the application.

Calc Sample

This sample program demonstrates the usage of control arrays.

Background

Adding controls with control arrays uses less resources than simply adding multiple controls of the same type to a form at design time.  Control arrays are also useful if you want several controls to share code.  The Calculator sample contains two control arrays [image] the number buttons and the operator buttons.  For more information, see Chapter 3, "Creating and Using Controls," in the Programmer's Guide.

File	Description

CALC.FRM	The main form containing two control arrays.

CALC.FRX	Binary data for the CALC.FRM file.

CALC.ICO	File containing icons used by the sample.

CALC.VBP	The project file for this sample application.

To Run

From the Visual Basic File menu, choose Open Project and select the CALC.VBP file, which is listed in the \SAMPLES\CALC subdirectory of the main Visual Basic directory.  Press F5 or choose Start from the Run menu to run the application.


Resource (ATM.VBP)

The ATM.VBP sample application demonstrates how to use a resource file.  This application produces the screen for an automated teller machine (ATM) that lets the user perform a bank transaction in one of several languages, such as English, French, or German.

Background

The ATM.VBP sample prompts the user to specify the language to conduct the transaction in.  Depending on the user's choice, the sample loads the appropriate group of resources from the ATM.RES file to continue the transaction.  For more information, see Chapter 4, "Managing Projects," in the Programmer's Guide.

File	Description

ATM.BAS	Module containing procedures for the sample.

ATM.RC	Resource source file containing all localized strings and references to ICO and WAV files, which are built into ATM.RES.

ATM.RES	Resource file containing text, icons, and sound (.WAV) data.  Results from running a resource compiler on the ATM.RC file.

ATM.VBP	The project file for this sample.

ATM32.RES	File containing resources for 32-bit systems.

FRMAMOUN.FRM	Form showing conversion of currencies into dollars.

FRMINPUT.FRM	Form for input of user information.

OPENBANK.FRM	Form for selecting a language.

OPENBANK.FRX	Binary data for the OPENBANK.FRM.

To Run

From the Visual Basic File menu, choose Open Project and select the ATM.VBP file, which is listed in the \SAMPLES\RESOURCE subdirectory of the main Visual Basic directory.  Press F5 or choose Start from the Run menu to run the application.


OLE Container (OLECONT.VBP)

This sample application demonstrates the capabilities of the OLE Container control.  The sample allows you to save or open OLE objects using the SaveToFile and ReadFromFile methods.  For more information, see Chapter 8, "Using the OLE Container Control," in the Programmer's Guide.

File	Description

CONTCHLD.FRM	An MDI child form containing the OLE Container control.

CONTMDI.FRM	The main form.

OLECONT.BAS	Module containing Public Sub and Function procedures.

COLECONT.VBP	The project file for this sample.

To Run

From the Visual Basic File menu, choose Open Project and select the OLECONT.VBP file, which is listed in the \SAMPLES\OLECONT subdirectory of the main Visual Basic directory.  Press F5 or choose Start from the Run menu to run the application.


Menus (TEXTEDIT.VBP)

The Menus sample is a simple text editor that demonstrates the handling of menus in Visual Basic.

File	Description

ABOUT.FRM	Form for the About box.

EDIT.FRM	The main form with standard text-editing menu items.

TEXTEDIT.BAS	Module containing Public Sub and Function procedures.

TEXTEDIT.VBP	The project file for this sample.

To Run

From the Visual Basic File menu, choose Open Project and select the TEXTEDIT.VBP file, which is listed in the \SAMPLES\MENUS subdirectory of the main Visual Basic directory.  Press F5 or choose Start from the Run menu to run the application.


Mouse (MOUSE.VBP)

This sample demonstrates many techniques discussed in Chapter 12, "Responding to Mouse Events," of the Programmer's Guide.

File	Description

CLICK.FRM	The form for the Click-A-Line application.

DRAG.FRM	The form for the Drag and Drop application.

DRAG.FRX	Binary data for the DRAG.FRM.

MOUSE.VBP	The project file for this sample.

SCRIBBLE.FRM	The form for the Scribble application.

SCMAIN.FRM	The main form.

To Run

From the Visual Basic File menu, choose Open Project and select the MOUSE.VBP file, which is listed in the \SAMPLES\MOUSE subdirectory of the main Visual Basic directory.  Press F5 or choose Start from the Run menu to run the application.


MDI Notepad (MDINOTE.VBP)

This sample is a simple text editor that demonstrates the multiple-document interface (MDI).  For more information, see Chapter 14, "Multiple-Document Interface (MDI) Applications," in the Programmer's Guide.

File	Description

FILOPEN.BAS	Module containing Public Sub and Function procedures for opening files.

FIND.FRM	Form used to find text.

MDI.FRM	The MDI form.

MDI.FRX	Binary data for the MDI.FRM file.

MDINOTE.BAS	Module containing Public Sub and Function procedures.

MDINOTE.VBP	The file project for this sample.

NOTEPAD.FRM	MDI child form for viewing text files.

To Run

From the Visual Basic File menu, choose Open Project and select the MDINOTE.VBP file, which is listed in the \SAMPLES\MDI subdirectory of the main Visual Basic directory.  Press F5 or choose Start from the Run menu to run the application.


Graphics (BLANKER.VBP)

This sample demonstrates some of the graphics techniques found in Chapter 15, "Creating Graphics for Applications," of the Programmer's Guide.  The sample uses the Image, Line, PictureBox, Shape, and Timer controls.

Background

The sample demonstrates several Visual Basic graphic methods, including: Circle, Line, Move, and PSet.

File	Description

BLANKER.FRM	The main form for the sample.

BLANKER.FRX	Binary data for the BLANKER.FRM file.

BLANKER.VBP	The project file for the sample.

To Run

From the Visual Basic File menu, choose Open Project and select the BLANKER.VBP file, which is listed in the \SAMPLES\GRAPHICS subdirectory of the main Visual Basic directory.  Press F5 or choose Start from the Run menu to run the application.


Alarm Clock (ALARM.VBP)

This sample demonstrates the Timer control.  For more information, see Chapter 17, "Interacting with the Environment," in the Programmer's Guide.

File	Description

ALARM.FRM	The main form for the sample containing the Timer control.

ALARM.FRX	Binary data for the ALARM.FRM file.

ALARM.VBP	The project file for this sample.

To Run

From the Visual Basic File menu, choose Open Project and select the ALARM.VBP file, which is listed in the \SAMPLES\ENVIR subdirectory of the main Visual Basic directory.  Press F5 or choose Start from the Run menu to run the application.


FileCtls (WINSEEK.VBP)

This sample application allows the user to search a directory for specific files, or files with a particular extension.  The sample uses file-system controls such as the File ListBox, Drive ListBox, and Directory ListBox controls.  For more information, see Chapter 18, "Using the File-System Controls," in the Programmer's Guide.

File	Description

SEEK.FRM	The main form for the sample.

WINSEEK.VBP	The project file for the sample.

To Run

From the Visual Basic File menu, choose Open Project and select the WINSEEK.VBP file, which is listed in the \SAMPLES\FILECTLS subdirectory of the main Visual Basic directory.  Press F5 or choose Start from the Run menu to run the application.


FileIO (RECEDIT.VBP)

This sample allows you to create a new database file and to add records to the new file.  The sample demonstrates file input/output methods.  For more information, see Chapter 19, "Processing Files," in the Programmer's Guide.

File	Description

FILEPROC.BAS	Module containing Public Sub and Function procedures for opening files.

RECEDIT.BAS	Module containing Public type definitions.

RECEDIT.FRM	The main form for the sample.

RECREDIT.VBP	The project file for the sample.

To Run

From the Visual Basic File menu, choose Open Project and select the RECEDIT.VBP file, which is listed in the \SAMPLES\FILEIO subdirectory of the main Visual Basic directory.  Press F5 or choose Start from the Run menu to run the application.


Datactrl (BIBLIO.VBP)

This sample allows you to browse the BIBLIO.MDB database, which is located in the main Visual Basic directory (\VB).  The sample demonstrates the Data control.  For more information, see Chapter 12, "Accessing Databases with the Data control," in the Programmer's Guide.

File	Description

BIBLIO.BAS	Module containing Public Sub and Function procedures.

BIBLIO.FRM	The main form for the sample application.

BIBLIO.HLP	Help file for the sample.

BIBLIO.VBP	Project file for the sample.

FRMABOUT.FRM	Form for the About box.

To Run

From the Visual Basic File menu, choose Open Project and select the BIBLIO.VBP file, which is listed in the \SAMPLES\DATCTRL subdirectory of the main Visual Basic directory.  Press F5 or choose Start from the Run menu to run the application.


Dynamic Data Exchange (DDE.VBP)

This sample demonstrates techniques for implementing Dynamic Data Exchange (DDE).  The sample allows you to link with various Microsoft applications and request information from them.  For more information on DDE, see Chapter 25, "Dynamic Data Exchange (DDE)," in the Programmer's Guide.

File	Description

DDE.BAS	Module containing Public constant declarations.

DDE.VBP	The project file for the sample application.

EXECUTE.FRM	Form that executes commands.

MAIN.FRM	The main form containing code to conduct DDE operations.

To Run

From the Visual Basic File menu, choose Open Project and select the DDE.VBP file, which is listed in the \SAMPLES\DDE subdirectory of the main Visual Basic directory.  Press F5 or choose Start from the Run menu to run the application.


CallDlls (CALLDLLS.VBP)

This sample demonstrates calling procedures in Dynamic-link libraries (DLLs).  For more information, see Chapter 26, "Calling Procedures in DLLs," of the Programmer's Guide.

File	Description

CALLDLLS.FRM	The main form for the application.

CALLDLLS.FRX	Binary data for the CALLDLLS.FRM file.

CALLDLLS.VBP	The project file for the application.

DECLARES.BAS	Module containing declarations of DLLs used in the sample.

FRMMENUS.FRM	Form for showing system information.

To Run

From the Visual Basic File menu, choose Open Project and select the CALLDLLS.VBP file, which is listed in the \SAMPLES\CALLDLLS subdirectory of the main Visual Basic directory.  Press F5 or choose Start from the Run menu to run the application.


Loan Calculator (LOAN.VBP)

This sample calculates loan payments after the user supplies basic information such as purchase amount, interest rate, and years to pay.  The sample uses the Grid control to display information.

File	Description

LOAN.FRM	The main form containing a Grid control.

LOAN.FRX	Binary data for the LOAN.FRM file.

LOAN.VBP	The project file for the sample application.

To Run

From the Visual Basic File menu, choose Open Project and select the LOAN.VBP file, which is listed in the \SAMPLES\GRID subdirectory of the main Visual Basic directory.  Press F5 or choose Start from the Run menu to run the application.


ListCombo Sample Application
ListCombo (LISTCOMBO.VBP)

This sample program demonstrates data binding to the standard ListBox and ComboBox controls.

Background

Visual Basic 4.0 allows you to bind the standard ListBox and ComboBox controls to a Data control.  Unlike other bound controls, the ListBox and ComboBox controls require that you populate the List portions of the control before binding in order to correctly display the current record's value in the control.

When binding to a ComboBox and ListBox control, the Data control selects the current record's value from the list of available entries within the control.  For example, binding the ListBox control to a field within a database which contains state abbreviations, the Data control will search the values within the ListBox and select the matching entry.  As a result, you must populate the control with all possible state abbreviations before binding the control.  If the ListBox is not populated, the Data control will not be able to find the matching entry and no item will be selected.

This sample application demonstrates this behavior and shows how to populate the ListBox and ComboBox controls prior to binding.  A single form is used to display the Publishers table contained within BIBLIO.MDB.  Publishers has a "state" field which contains the state abbreviation of the current Publisher's address.  At runtime, the sample performs a query of the Publishers table of all distinct values contained within the state field and populates a ListBox and ComboBox control.  Then, the controls are bound to the Data control.

When the user cycles through the Publishers records using the navigation buttons on the Data control, the "state" field value for the current record is selected in the ListBox and ComboBox controls.  The user can then choose which of these controls to view by clicking on the appropriate option buttons.

File	Description

FRMPUB.FRM	The main Publishers form, which displays the Publishers records.

FRMPUB.FRX	The binary portion of the Publishers form.

FRMABOUT.FRM	Standard About form.

FRMABOUT.FRX	The binary portion of the About form.

LISTCMBO.VBP	The project file for the sample application.

To Run

From the Visual Basic File menu, choose Open Project and select the LISTCMBO.VBP file, which is listed in the \SAMPLES\LISTCMBO subdirectory of the main Visual Basic directory.  Press F5 or choose Start from the Run menu to run the application.

To cycle through the records, click on the navigation buttons on the Data control.  To view either the ListBox or ComboBox controls, click on the appropriate option buttons.


MAPI Sample Application
MAPI Sample Application (VBMAIL.VBP)

This sample program demonstrates the use of the MAPI controls by sending and receiving electronic mail.  It uses the messaging application programming interface (MAPI) controls: MAPI messages and MAPI session.

Note   To run this sample, you need a MAPI-compliant messaging system, such as the one contained in Microsoft Windows for Workgroups.  If you are using Windows 95, you will need Microsoft Exchange.

Background

The MAPI session control establishes a MAPI session and signs off from a MAPI session.  The MAPI messages control allows you to perform a variety of messaging systems functions after a messaging session has been established.  These functions include accessing, downloading, and sending messages, displaying the details and address book dialog boxes, accessing data attachments, resolving recipient names during addressing, and performing compose, reply, reply-all, forward, and deleting actions on messages.

File	Description

MAILLST.FRM	Form for displaying the list of mail messages.

MAILST.FRX	Contains binary data for the sample.

MAILOPTF.FRM	Form for setting options.

MAILSUP.BAS	Module of support procedures for the example.

MSGVIEW.FRM	Form in which a viewed message is displayed.

NEWMSG.FRM	Form for creating a new message.

VBMAIL.FRM	The main form.

VBMAIL.VBP	The project file for this sample application.

To Run

From the Visual Basic File menu, choose Open Project and select the VBMAIL.VBP file, which is listed in the \SAMPLES\MAPI subdirectory of the main Visual Basic directory.  Press F5 or choose Start from the Run menu to run the application.


Multimedia MCI Sample Application
Multimedia MCI Sample Application (MCITEST.VBP)

This sample program demonstrates the use of some of the device types supported by the Media Control Interface (MCI).  The three device types used in this program are listed in the following table.

Device Type	Description

CDAudio	Plays audio discs from the CD-ROM drive.

Sequencer	Plays MIDI sequencer sound files (*.MID).

WaveAudio	Plays digitized waveform sound files (*.WAV).

Hardware Requirements:

To access a CD-ROM drive or a sound card, the hardware, along with any supporting device drivers, should be installed and configured for the machine.  The following table lists the hardware required for the MCI device types used in this program.

Device type	Hardware

CDAudio	CD-ROM drive.

Sequencer	Sound card (for instance, Sound Blaster Pro)

WaveAudio	Sound card.

Software Requirements

For the multimedia MCI control to work, MCI services must be present.  These services are provided in the Microsoft Windows operating system version 3.1.

To access a specific MCI device type, the corresponding MCI device driver must be installed.  The following table lists the device drivers required for the MCI device types used in this program.

Device type	Device driver

CDAudio	MCICDA.DRV

Sequencer	MCISEQ.DRV

WaveAudio	MCIWAVE.DRV

The [mci] section of the SYSTEM.INI file contains a list of the installed MCI device types.  This is what your file would look like if all three of the above device types were installed:

[mci]

CDAudio=mcicda.drv

WaveAudio=mciwave.drv

Sequencer=mciseq.drv

Background

The multimedia MCI control provides a high-level interface for using multimedia devices.  Using the property settings of a control, you can determine the settings and actions of a device.

The multimedia MCI control can also recognize what actions are relevant for the current state of a device.  For example, if you click a "Pause" button while playing a movie, the "Play" button is automatically re-enabled.

File	Description

ABOUTBOX.FRM	Form for the About box.

ABOUTBOX.FRX	The binary portion of the About box form.

CD.FRM	The form for playing compact disc audio.

CD.FRX	The binary portion of the compact disc form.

GLOBAL.BAS	Public data types and declarations.

MCITEST.BAS	Public Sub and Function procedures.

MCITEST.FRM	The main form.

MCITEST.FRX	The binary portion of the main form.

MCITEST.VBP	The project file for this sample application.

MCITEST.MID	Sample MIDI sequencer file.

MCITEST.WAV	Sample waveform file.

OPENDLG.FRM	Form for holding the common dialog control.

WAVE.FRM	Form for playing waveform and MIDI files.

To Run

From the Visual Basic File menu, choose Open Project and select the MCITEST.VBP file, which is listed in the \SAMPLES\MCI subdirectory of the main Visual Basic directory.  Press F5 or choose Start from the Run menu to run the application.


Outline Sample Application (PHONE.VBP)

This sample program demonstrates the use of the Outline control with an address book database application.

Background

The Outline control allows users to graphically present hierarchically structured data in a variety of ways.

File	Description

FIRSTTAB.BMP	Bitmap for the project.

LASTTAB.BMP	Bitmap for the project.

MIDTAB.BMP	Bitmap for the project.

PHONE.FRM	The main form.

PHONE.FRX	The binary portion of the main form.

PHONE.MDB	Database file.

PHONE.VBP	The project file for the sample application.

To Run

From the Visual Basic File menu, choose Open Project and select the PHONE.VBP file, which is listed in the \SAMPLES\OUTLINE subdirectory of the main Visual Basic directory.  Press F5 or choose Start from the Run menu to run the application.


Picture Clip Sample Application
Picture Clip Sample Application (REDTOP.VBP)

This sample program demonstrates one of the many possible uses of the PictureClip control.

Background

This sample application uses the PictureClip control to spin a top.

File	Description

INFOFORM.FRM	The information form.

INFOFORM.FRX	The binary portion of the information form.

REDTOP.FRM	The main form.

REDTOP.FRX	The binary portion of the main form.

REDTOP.VBP	The project file for the sample application.

To Run

From the Visual Basic File menu, choose Open Project and select the REDTOP.VBP file, which is listed in the \SAMPLES\PICCLIP subdirectory of the main Visual Basic directory. Press F5 or choose Start from the Run menu to run the application.


VisData
VisData (VISDATA.VBP)

This sample program demonstrates various programming techniques used to access data through the Data Access Object (DAO) layer built into the Visual Basic Professional Edition.

Note   To access ODBC data sources with this sample, you must first install ODBC using the ODBC setup program provided with Visual Basic, Professional Edition.

VisData behaves like a general purpose database utility, capable of the following functions:

Database and table creation.

Table modification (adding and deleting fields and indexes).

Data browsing/modifying using the three recordset types (table, dynaset, and snapshot) and three form types (single record, data control, and data grid).

Property browsing on all objects.

Form demonstrating the new data-bound list and data-bound combo box controls.

Import/export to all supported data types.

Direct SQL statement execution for any SQL supported functions such as Insert, Update, Delete, Drop, Create, Dump, and so forth.

AdHoc Query builder that helps users unfamiliar with SQL to create complex queries with Where clauses, Joins, Order By, and Group By expressions while limiting output to selected columns.

Transaction processing.

Copying table structures and data to the same or different database.

Support of Jet MDB, Dbase III and IV, FoxPro 2.x, Paradox 3.x and 4.x, Btrieve, Text, Excel, and SQL Server, both DDL and DML.

QueryDef creation, modification, and execution.

JET security creation/modification.

Relation/referential Integrity creation and modification.

Management of attached tables.

Use as an add-in to Visual Basic (see VISDATA.TXT).

The code contains comments to help explain the use of the various methods in the data access layer.  Code and forms may be copied from this application to other applications with minimal modification.

File	Description

ABOUTBOX.FRM	Standard About box for the application.

ADDFIELD.FRM	Form to add fields to tables.

ADDINDEX.FRM	Form used to add indexes to Tables.

ADDUDP.FRM	Form to add user-defined properties.

ATTACH.FRM	Attached table list.

CPYSTRU.FRM	Form to copy table structures.

DATAFORM.FRM	Data control form.

DATAGRID.FRM	Form used to display data in a data-bound grid control.

DATATYPE.FRM	Data type selector for import/export utility.

DCPROP.FRM	Data control property form.

DFD.FRM	Data Form Designer add-in form.

DYNASNAP.FRM	Form to display data in single-record mode.

ERRORS.FRM	Errors collection form.

EXPNAME.FRM	Export name prompt.

FIND.FRM	Form used to find records in a Dynaset.

GRPSUSRS.FRM	Jet security form.

IMPTBLS.FRM	Import tables list.

JOIN.FRM	Form used to add joins to the Query Builder.

LISTCBO.FRM	DBList and DBCombo form.

LOGINFRM.FRM	Jet WorkSpace logon dialog box.

MUOPT.FRM	Multiuser options dialog.

NEWATTCH.FRM	New attachment form.

NEWPW.FRM	New password dialog.

NEWUG.FRM	New User/Group dialog.

OPENDB.FRM	Form used to open an ODBC database.

PROPSHT.FRM	Property browser.

QUERY.FRM	Form used to build queries.

RELATION.FRM	Jet Relations browser.

REPLACE.FRM	Form to perform global replace operations on a table.

SEEK.FRM	Form used to get input for the Seek function.

SQL.FRM	Form to enter and execute SQL statements.

TABLEOBJ.FRM	Form used to display data in a Table object.

TABLES.FRM	Form used to display table lists.

TBLSTRU.FRM	Form to display and modify table structures.

VBIMEX.BAS	Import/export-specific code.

VBIMEX.FRM	Import/export form.

VDADDIN.BAS	Add-in stub code.

VDADDIN.CLS	Add-in stub class module.

VDADDIN.VBP	Add-in project file.

VDCLASS.CLS	Class module for VisData.

VDMDI.FRM	Main MDI form for the application.

VISDATA.BAS	Support functions for the application.

VISDATA.HLP	VisData Help File.

VISDATA.VBP	Project file for the application.

ZOOM.FRM	Form to zoom in on character data.

.FRX Files	Contains binary data for the associated .FRM File.

.ICO Files	Supplied for modification by user.

To Run

From the File menu, choose Open Project, and select the VISDATA.VBP file, which is located in the \SAMPLES\VISDATA subdirectory of the main Visual Basic directory.

If you want to open a local database, you simply need to choose the type of database, and a File Open dialog box will be displayed with the file type set to the requested data file type.

If you choose ODBC on the Open Database submenu, you will then see the Open DataBase form.  Since you probably have no servers entered, you will need to enter a name for an existing SQL server on your network.  If you already know the user ID and password, you can add them as well.  The Database name is optional.  Once you have entered this data, choose OK, and you should be able to log on to the server.  You may get some more dialogs in the process.  Answer any questions you can and ask the SQL administrator for help if you run into problems or don't know some of the parameters.

Once a database is open, double-clicking a table name will open the table in the selected form type and recordset type.  Use the Query Builder to create dynasets with selected data from one or more tables at a time.

The table-type Recordset is always updatable.  The dynaset-type Recordset will be updatable in most cases except on ODBC with no unique index, certain multiple table joins, and other SQL Select statements, such as count(*), max(), and so forth.  The snapshot-type Recordset is never updatable.

Making VisData an Add-In

The VisData sample application is designed to be an OLE Automation server.  It is supplied with another small application called VDADDIN.VBP, which makes it possible to have VisData appear on the Add-Ins menu in the Visual Basic development environment.  Below is a step-by-step process you need to follow to achieve this functionality.  It is also an example of how you can make any application an add-in without having it load every time Visual Basic is loaded.

1.	Load Visual Basic.

2.	Open VDADDIN.VBP (located in the \VB\SAMPLES\VISDATA directory).

3.	From the File menu, choose Make EXE File to make an .EXE file called VDADDxx.EXE, where xx = 16 or 32, depending on the platform you are using.

4.	Load VISDATA.VBP (located in the \VB\SAMPLES\VISDATA directory).

5.	Make an .EXE file called VISDATxx.EXE in the same directory in which you placed VDADDxx.EXE.

6.	Close Visual Basic.

7.	Run the VisData executable file.

8.	From the File menu, choose the Make VisData a VB Add-In command.

9.	Close VisData.

10.	Load Visual Basic again.

11.	When you click the Add-Ins menu, you should see VisData on the menu.

If you would like to have 16-bit and 32-bit versions on the same machine, you must execute a few more steps after creating the first set of .EXE files.

1.	If you already created a 16-bit .EXE file, then load the 32-bit version of Visual Basic; otherwise, load the 16-bit version of Visual Basic.

2.	Open VDADDIN.VBP.

3.	From the Tools menu, choose Project Options.

4.	In the Compatible Object Application field, enter the name of the .EXE file you have already built (for instance, VDADD16.EXE).

5.	Choose OK.

6.	Make an .EXE file using a name that is different from the existing .EXE file.  (For example, if you already made VDADD16.EXE, you should use VDADD32.EXE.)

7.	Repeat steps 2 through 6 with VISDATA.VBP.


Communications Sample Applications

Vbterm.vbp	Dialer.vbp

VBTERM Sample Application

VBTERM is a terminal emulation program using  the Communications control. It illustrates how to use the Communications control with a serial port.

Background

The Communications control allows you to open a serial port, change its settings, send and receive data through the port, and monitor and set many of the different data lines.  Its dual-method access allows for both polling and event-driven communications.

File	Description

CANSEND.FRM	Dialog box used during file transfer.

TERMSET.FRM	Form used to change the serial port settings.

TERMSET.FRX	Binary portion of TERMSET.FRM.

VBTERM.FRM	The main form.

VBTERM.FRX	Binary portion of VBTERM.FRM.

VBTERM.GLO	Public declarations.

VBTERM.VBP	The project file for the sample application.

To Run

From the Visual Basic File menu, choose Open Project and select the VBTERM.VBP file, which is listed in the \SAMPLES\VBTERM subdirectory of the main Visual Basic directory.  Press F5 or choose Start from the Run menu to run the application.

Dialer Sample Application

The Dialer sample application demonstrates how to dial out using the Communications control with a modem.

File	Description

DIALER.FRM	The main form.

DIALER.VBP	The project file for the sample application.

To Run

From the Visual Basic File menu, choose Open Project and select the DIALER.VBP file, which is listed in the \SAMPLES\VBTERM subdirectory of the main Visual Basic directory.  Press F5 or choose Start from the Run menu to run the application.


OLE Automation Sample Applications

DS.vbp	ThingTst.vbp	LoginDlg.vbp	DlgTest.vbp 	LoginDlg.xls	Gravity.vbp	Gravtest.vbp

DemoServer Sample Application

DemoServer (DS.VBP) illustrates the basics of class creation, and demonstrates the lifetime of objects.

The Thing object provided by this OLE server can be accessed by any OLE Automation client.  THINGTST.VBP is a Visual Basic project that uses the Thing class defined in the DemoServer application.

Background

The code in DemoServer is developed and explained in the step-by-step procedure in Chapter 2, "Creating Your First OLE Server," in the Professional Features book Creating OLE Servers.

The Thing class contains an example of a read-only property implemented using Property Get, and an example method.  Code in the Initialize and Terminate events of the class gives a visible indication of the order of events when objects are created and destroyed.

File	Description

DS.VBP	The project file for the sample application.

DS_THING.CLS	The class module that defines the Thing object.

DS_MAIN.BAS	A standard module containing the Sub Main procedure.

To Run

From the Visual Basic File menu, choose Open Project and select the DS.VBP file, which is listed in the \SAMPLES\OLESERV subdirectory of the main Visual Basic directory.  Press F5 or choose Start With Full Compile from the Run menu to run the application.

You should always fully compile an OLE server project when you start it, because errors detected after your client application is running may require restarting the OLE server project, leaving your client application with invalid object references.

While running, the project temporarily registers its classes in the Windows Registry. You can then start a second instance of Visual Basic and load THINGTST.VBP, an OLE Automation client that creates instances of the Thing class.  See the description for the ThingTst sample application for instructions.

ThingTest Sample Application

This sample program is an OLE Automation client that uses the Thing object exposed by the DemoServer sample application (DS.VBP).

Background

The code in ThingTest is developed and explained in the step-by-step procedure in Chapter 2, "Creating Your First OLE Server," in the Professional Features book Creating OLE Servers.

ThingTest creates a Thing object in its Form_Load event procedure.  Buttons on the main form display the object's properties, call its method, and destroy and recreate it.  The lifetime of the object is demonstrated by message boxes displayed in the object's Initialize and Terminate events.

File	Description

THINGTST.VBP	The project file for this sample application.

THINGTST.FRM	The form displayed by the application.

To Run

First run the DemoServer sample (DS.VBP), as described earlier.  ThingTest cannot run unless the OLE server it refers to is already running.

From the Visual Basic File menu, choose Open Project and select the THINGTST.VBP file, which is listed in the \SAMPLES\OLESERV subdirectory of the main Visual Basic directory. Press F5 or choose Start from the Run menu to run the application.

An InputBox prompts you for a value to assign to the Name property of the Thing object created in the form's Load event procedure.  Type a name and click OK.  The Thing object's Initialize event displays a message box showing the Name property and the read-only Created property.

The message box may not be visible, because it belongs to the OLE server.  If you attempt to drag or resize the Debug window, or any other window in the ThingTest project, a Server Busy dialog box appears.  Clicking Switch To brings the server's message box to the front.  You will have to use the Server Busy dialog box several times while executing this sample.  In a real OLE server, the Initialize and Terminate events would never include code that interacts with the user.

The Name property is blank, because it cannot be assigned until the Initialize event has finished.  Click OK.  The form for the ThingTest sample appears.  Click Show the Thing to display the Thing object's properties.  Click Reverse the Thing's Name to demonstrate the ReverseName method.

The reference to the Thing object is stored in a variable in the Form module, so the Thing lasts as long as the form does.  You can destroy the Thing and create a new one by clicking Create New Thing.  You will get a message box from the Terminate event of the old Thing, and then an InputBox prompting you for a name for a new Thing.  You may have to use the Server Busy dialog box to make the message boxes visible.

You can demonstrate object variable scope by clicking Temporary Thing.  The variable that holds the reference to this second Thing object is declared in the Click event for the button, so it goes out of scope when the Click event ends.  You will see the InputBox, the Initialize message box, and then the message box from the Terminate event, one after the other.

Close ThingTest by clicking the close button, and observe the Terminate event message box for the Thing object that belonged to the form.

Run the project again, and this time end it by clicking the End button on the toolbar, or by choosing End from the Run menu.  The Terminate message box for the form's Thing object is not displayed.

Important   Ending your program with the End button, or with an End statement in your code, halts the program immediately, without executing the Terminate events of any objects. It is always better to shut your program down by unloading all the forms.

Login Dialog Sample Application

Login Dialog illustrates the use of an in-process OLE server (DLL) to display a standard user interface element, in this case a dialog box for a database login.

The SQLLoginDialog object provided by this OLE server can be accessed by any OLE Automation client.  DLGTEST.VBP is a Visual Basic project that uses this object.  If you have Microsoft Excel installed on your computer, you can also use LOGINDLG.XLS to access the SQLLoginDialog object from Microsoft Excel.

Background

The code in the Login Dialog server is developed and explained in the step-by-step procedure in Chapter 4, "In-Process OLE Servers," in the Professional Features book Creating OLE Servers.

The SQLLoginDialog class contains one method, Show, which is used to display the login dialog box.

File	Description

LOGINDLG.VBP	The project file for the sample application.

LOGINDLG.CLS	The class module that defines the SQLLoginDialog object.

LOGINDLG.FRM	The dialog box form.

LOGINDLG.BAS	A standard module containing the Sub Main procedure.

To Run as an Out-of-Process Server

From the Visual Basic File menu, choose Open Project and select the LOGINDLG.VBP file, which is listed in the \SAMPLES\OLESERV subdirectory of the main Visual Basic directory.  Press Ctrl+F5 or choose Start With Full Compile from the Run menu to run the application.

You should always fully compile an OLE server project when you start it.  Errors detected after your client application is running may require restarting the OLE server project, leaving your client application with invalid object references.

While running, the project temporarily registers its classes in the Windows Registry. You can then start a second instance of Visual Basic and load DLGTEST.VBP, an OLE Automation client that creates instances of the SQLLoginDialog class, or LOGINDLG.XLS, a Microsoft Excel workbook that uses SQLLoginDialog objects.

See the descriptions for the DialogTest sample application and the LoginDlg.XLS workbook for instructions.

To Run as an In-Process Server

From the Visual Basic File menu, choose Open Project and select the LOGINDLG.VBP file, which is listed in the \SAMPLES\OLESERV subdirectory of the main Visual Basic directory.

From the Tools menu, choose Options.  Select the Advanced tab of the Options dialog box, and make sure that Use OLE DLL Restrictions is checked, so that restrictions for in-process OLE servers will be used.  For example, in-process servers cannot display modeless forms.  Use this option whenever you debug an OLE server that will be compiled as an in-process OLE server, using Make OLE DLL File.

From the File menu, choose Make OLE DLL File.  Enter LOGINDLG.DLL as the File name, and click OK.

When the DLL has been created, minimize Visual Basic.  Do not start the project in the development environment.

See the descriptions for the DialogTest sample application and the LoginDlg.XLS workbook for instructions.

DialogTest Sample Application

This sample program is an OLE Automation client that uses the SQLLoginDialog object exposed by the Login Dialog sample application (LOGINDLG.VBP).

Background

The code in the DialogTest client application is developed and explained in the step-by-step procedure in Chapter 4, "In-Process OLE Servers," in the Professional Features book Creating OLE Servers.

DialogTest creates a SQLLoginDialog object in its Form_Load event procedure.  When you fill in the login information and press OK, a message box containing the resulting login string is displayed.  A button on the main form repeats the process.

File	Description

DLGTEST.VBP	The project file for this sample application.

DLGTEST.FRM	The form displayed by the application.

To Run with Login Dialog as an Out-of-Process Server

First run the Login Dialog sample (LOGINDLG.VBP), as described earlier.  DialogTest cannot run unless the OLE server it refers to is already running.

From the Visual Basic File menu, choose Open Project and select the DLGTEST.VBP file, which is listed in the \SAMPLES\OLESERV subdirectory of the main Visual Basic directory. Press F5 or choose Start from the Run menu to run the application.  The startup form's Load event procedure creates a SQLLoginDialog object and calls its Show method.

The login dialog box may not be visible initially, because it belongs to the OLE server, and may be hidden behind the windows of the DialogTest project.  If you attempt to drag or resize the Debug window, or any other window in the DialogTest project, a Server Busy dialog box appears.  Clicking Switch To brings the login dialog box to the front.

You will have to use the Server Busy dialog box again every time you use the button on the form to re-display the login dialog.  When the Login Dialog runs as an in-process OLE server, the dialog box will automatically come to the front, and the Server Busy dialog will never appear.

Type a password and click OK.  A message box displays the SQL login string returned by the Show method, including your password value.  Click the button on the form to call the Show method again.

To Run with Login Dialog as an In-Process Server

First compile the Login Dialog sample (LOGINDLG.VBP) as an in-process OLE server, as described earlier.  Do not run the Login Dialog sample in the Design environment.

From the Visual Basic File menu, choose Open Project and select the DLGTEST.VBP file, which is listed in the \SAMPLES\OLESERV subdirectory of the main Visual Basic directory.  From the Tools menu, choose References.  In the References dialog box, locate the entry for Standard Login Dialogs and unselect it.  The information panel at the bottom of the dialog box should show the path for LOGINDLG.VBP, and the entry should be marked MISSING beside the check box, because the OLE server project has not been started.

Locate the entry for Standard Login Dialogs that shows the path LOGINDLG.DLL in the information panel.  Select this entry, and click OK.

Press F5 or choose Start from the Run menu to run the application.  The startup form's Load event procedure creates a SQLLoginDialog object and calls its Show method. Type a password and click OK.  A message box displays the SQL login string returned by the Show method, including your password value.

You can repeat the process by clicking the button on the form.

LoginDlg.XLS Sample Application

This sample is a Microsoft Excel workbook that uses the SQLLoginDialog object exposed by the Login Dialog sample application (LOGINDLG.VBP).

Important   You must have a 32-bit version of Microsoft Excel installed on your computer to use this sample.

Background

A button on the worksheet in LoginDlg.XLS calls a Visual Basic for an applications procedure, which creates a SQLLoginDialog object and shows its dialog box.  When you fill in the login information and press OK, a message box containing the resulting login string is displayed.

File	Description

LOGINDLG.XLS	The Microsoft Excel workbook.

To Run with Login Dialog as an Out-of-Process Server

First run the Login Dialog sample (LOGINDLG.VBP), as described earlier.  This sample cannot run unless the OLE server it refers to is already running.

Start Microsoft Excel.  From the File menu, choose Open and select the LOGINDLG.XLS file, which is listed in the \SAMPLES\OLESERV subdirectory of the main Visual Basic directory. Click the Login to the Corporate Widgets Database button on worksheet.

The login dialog box may not be visible initially, because it belongs to the OLE server, and may be hidden behind Microsoft Excel.  If you click on the worksheet, a Server Busy dialog box appears.  Clicking Switch To brings the login dialog box to the front.

You will have to use the Server Busy dialog box again every time you use the button to display the login dialog.  When the Login Dialog runs as an in-process OLE server, the dialog box will automatically come to the front, and the Server Busy dialog will never appear.

Type a password and click OK.  A message box displays the SQL login string returned by the Show method, including your password value.  Click the button on the worksheet to call the Show method again.

To Run with Login Dialog as an In-Process Server

First compile the Login Dialog sample (LOGINDLG.VBP) as an in-process OLE server, as described earlier.  Do not run the Login Dialog sample in the Design environment.

Start Microsoft Excel.  From the File menu, choose Open and select the LOGINDLG.XLS file, which is listed in the \SAMPLES\OLESERV subdirectory of the main Visual Basic directory.  Using the tabs at the bottom of the worksheet, select Module1, the code module that contains the Click event code for the button.

From the Tools menu, choose References.  In the References dialog box, locate the entry for Standard Login Dialogs and unselect it.  The information panel at the bottom of the dialog box should show the path for LOGINDLG.VBP, and the entry should be marked MISSING beside the check box, because the OLE server project has not been started.

Locate the entry for Standard Login Dialogs that shows the path LOGINDLG.DLL in the information panel.  Select this entry, and click OK.

Use the tabs at the bottom of the module sheet to return to the worksheet, Sheet1.  Click the Login to the Corporate Widgets Database button on the worksheet.

When the login dialog appears, type a password and click OK.  A message box displays the SQL login string returned by the Show method, including your password value.  Click the button on the worksheet to call the Show method again.

Gravity Sample Application

This sample application illustrates how to create OLE Automation objects in an OLE server.  The classes defined in this project can be accessed by any OLE Automation client, such as the GRAVTEST.VBP sample application.

Background

Starting from the moment the Throw method of the Ball object is called, the read-only Distance and Height properties report the ball's location at any subsequent time.

File	Description

GRAVITY.VBP	The project file for this sample application.

GRAVITY.CLS	The public class module (Ball object).

GRAVITY.BAS	A standard module containing the Sub Main procedure.

To Run

From the Visual Basic File menu, choose Open Project and select the GRAVITY.VBP file, which is listed in the \SAMPLES\OLESERV subdirectory of the main Visual Basic directory. Press F5 or choose Start With Full Compile from the Run menu to run the application.

You should always fully compile an OLE server project when you start it because errors detected after your client application is running may require restarting the OLE server project, leaving your client application with invalid object references.

Once running, this project temporarily registers its classes in the system registry. You can then start a second instance of Visual Basic to run an OLE client to create instances of the classes.  See the instructions for the Gravity Test Sample Application, GRAVTEST.VBP.

Gravity Test Sample Application

This sample application illustrates how to create instances of the classes defined in and exposed by an OLE Automation server, GRAVITY.VBP.

Background

This sample application presents the user interface for tracking a projectile across the active window and uses the objects, properties, and methods defined in GRAVITY.VBP.

File	Description

GRAVTEST.BAS	A standard module.

GRAVTEST.FRM	Form used for user input.

GRAVTEST.VBP	The project file for this sample application.

To Run

First run the Gravity sample (GRAVITY.VBP), as described earlier.  The Gravity Test sample cannot run unless the OLE server it refers to is already running.

From the Visual Basic File menu, choose Open Project and select the GRAVTEST.VBP file, which is listed in the \SAMPLES\OLESERV subdirectory of the main Visual Basic directory.  Press F5 to run GRAVTEST.VBP.

Click in the rectangle in the lower left corner of the form, and drag the mouse to create a velocity vector to describe the initial speed and direction of the ball.  Hint: Start with a short vector, because you can't interrupt the throw.  (If you make a long vector, click and drag again to start over.)

Press the Throw button to call the Throw method of the ball.  The ball's progress will be plotted by a timer which calls the Distance and Height properties of the ball at succeeding timer events.


Add-ins Sample Applications
Add-ins Sample Applications (SPY.VBP, ALIGN.VBP)

Spy.vbp	Align.vbp

Important   If you want to permanently register add-ins, follow this procedure.

1.	Make an executable file by choosing Make EXE File from the File menu.

2.	Run the .EXE file with the /REGSERVER command-line argument.  For example,

SPY16.EXE /REGSERVER

This will permanently register the add-in, and then immediately close the add-in.

Spy Sample Application

This program shows how to write a Visual Basic add-in in Visual Basic to connect to the file control events that take place in Visual Basic.  This program, when installed and enabled in an instance of Visual Basic, will display all file control events and all the parameters of the events.

Background

Visual Basic has exposed some interfaces in its development environment to allow object applications (OLE Automation servers) to respond to certain events within Visual Basic and to manipulate certain elements of the current project.  These object applications that are added to the Visual Basic development environment are known as add-ins.  Some of the Visual Basic events that the add-in can respond to are events for loading, saving, deleting, and renaming the files of a project.  Visual Basic notifies the add-in through events when a file or files of a project are about to be loaded, saved, or renamed.

In addition, Visual Basic can now be used to create object applications (OLE Automation servers).  With this capability, Visual Basic can be used to write an object application that can be used as an add-in to the Visual Basic development environment.

File	Description

ABOUT.FRM	Form that displays information about the example.  Click with the right mouse button on the File Event Spy form to see this form.

EVENTSPY.CLS	Class that is connected to the file event interface.

MAIN.BAS	Standard module of support procedures.

SPY.CLS	Class that is connected to the Spy menu item and the add-in interface.

SPY.VBP	The project file for the sample application.

SPYSHOW.FRM	Form that displays the event information.

To Run

From the Visual Basic File menu, choose Open Project and select the SPY.VBP file, which is listed in the \SAMPLES\SPY subdirectory of the main Visual Basic directory.

You can then start the add-in by running the example.  (Press F5 or choose Start from the Run menu to run the application.)

Once the add-in is running, it is temporarily registered in the system registry.  If you want to permanently register the add-in, follow the instructions at the beginning of Section 9:  Add-ins Sample Applications.

Once the add-in is registered, you can then start another instance of Visual Basic.  From the Add-Ins menu, choose Add-In Manager, and then select the check box next to the Event Spy add-in.  Once you do this, all file events for the new instance of Visual Basic will be displayed in the File Events form (SPYFORM.FRM).

Align Sample Application

This application shows how to write a Visual Basic add-in using Visual Basic.  It demonstrates how to add a menu and menu items to the Add-Ins menu in the Visual Basic development environment, and manipulate properties of controls on a form.  This program, when installed in an instance of Visual Basic, will align or size all selected controls on a form to each other.

Background

Visual Basic has exposed some interfaces in its development environment to allow object applications to respond to certain events within Visual Basic and to manipulate certain elements of the current project.  These object applications that are added to the Visual Basic development environment are known as add-ins.  Some of the Visual Basic events that the add-in can respond to are events caused by selecting a menu item in a menu that was added to the Add-Ins menu by the add-in.

Also, the add-in can retrieve and change properties of the currently enabled form and controls on the form.  Using these capabilities, this example will align all currently selected controls on a form.  The controls will be aligned to the left-, right-, top-, or bottom-most edge of the selected controls.  The align sample also provides a Size menu item to synchronize the width and height of selected controls.

In addition, Visual Basic can now be used to write object applications.  With this capability, Visual Basic can be used to create an object application that can be used as an add-in to the Visual Basic development environment.

File	Description

ABOUT.FRM	Form that displays information about the example.

ALIGN.CLS	Connector class.  The class that is connected to the add-in interface.  Exposes a ConnectAddin method to connect the add, a DisconnectAddin method to disconnect the add-in, and an AfterClick method corresponding to showing the About box in response to a menu click.

ALIGN.VBP	The project file for the sample application.

ALIGNALL.CLS	The AfterClick event of instances of this class is connected to menu items on the Align submenu of the Visual Basic Add-Ins menu.  The type of alignment (Left, Right, Top, Bottom) is determined by properties on the instance of the class.

MAIN.BAS	Standard module of support procedures.  Modifies the VB.INI file to find the loaded add-in.

SIZEALL.CLS	The AfterClick event of instances of this class is connected to menu items on the Size menu of the Visual Basic Add-Ins menu.  The type of sizing (Width, Height, or Both) is determined by a property of the class.

To Run

From the Visual Basic File menu, choose Open Project and select the ALIGN.VBP file, which is listed in the \SAMPLES\ALIGN subdirectory of the main Visual Basic directory.

You can then start the add-in by running ALIGN.VBP. (Press F5 or choose Start from the Run menu to run the application.)

Once the add-in is running, it is temporarily registered in the system registry.  If you want to permanently register the add-in, follow the instructions at the beginning of Section 9:  Add-ins Sample Applications.

Once the add-in is registered, you can then start another instance of Visual Basic.  From the Add-Ins menu, choose Add-In Manager, and then select the check box next to the 'Align Sample Add-In' add-in.

Once this is done, select the controls you want to align on a form, and then choose the type of alignment by choosing a menu item on the Align submenu of the Add-Ins menu.  The add-in will then align the selected edge of all the currently selected controls.  You can also size controls in a similar fashion.  The controls are sized based on the size of the first selected control.

Note    You can't use the Align menu command if you have selected a Line or Timer control, or any other control that doesn't support position properties.


Data Form Designer (DFD.VBP)

This sample application uses the IDE extensibility in Visual Basic 4.0 to create a Data Form Designer (Wizard) capable of adding forms to the current Visual Basic project.

This sample program illustrates how to create a powerful Visual Basic add-in that performs a normally tedious task in a few easy steps. It performs the following functions:

1.	Creates and adds a new form to the current Visual Basic project.

2.	Adds a label with the field name for each field.

3.	Adds a bound control for each field (TextBox for string, date, and numeric data; CheckBox for Boolean; multiple-line TextBox for memo field; and OLE Container for binary data)

4.	Adds command buttons to perform various data access functions.

5.	Adds code behind the command buttons and the data control with liberal comments.

File	Description

DFD.FRM	Main form.

DFD.FRX	Binary data for the main form.

DFD.VBP	Project file for the add-in.

DFDCLASS.CLS	Class module.

MODDFD.BAS	Support code.

The following is a step-by-step example of how to use the Data Form Designer.

1.	Load Visual Basic 4.0.

2.	From the Add-Ins menu, choose Add-In Manager.

3.	Select the check box next to the Data Form Designer add-in (this makes it available), and then choose OK.

4.	From the Add-Ins menu, choose Data Form Designer.

5.	Enter a form name (1-8 characters, no spaces).

6.	Select or enter a Connect string.

7.	Open a database.

8.	Select or enter a RecordSource.

9.	Select the fields to include (choosing ">>" selects all fields).

10.	Order fields with Drag/Drop in the list.

11.	Select Build the Form.

12.	Watch it build the form in your project.

13.	Add another form or close the Data Form Designer.

14.	Add a form load in your project for the newly created form. Its name will be the name you entered, prefixed with "frm".

15.	Run your application and execute the form load to see how the new form works.


Crystal Reports (CROCXSAM.VBP)

The Crystal Reports sample application demonstrates how to use the Crystal Reports custom control to add report writing capabilities to your application and enable your users to customize a report before they use it.

File	Description

CROCXSAM.VBP	The project file for this sample application.

FORM1.FRM	The main form.

FORM2.FRM	Printer options form.

FORM3.FRM	Print to File settings form.

To Run

From the Visual Basic File menu, choose Open Project and select the CROCXSAM.VBP file, which is listed in the \REPORT subdirectory of the main Visual Basic directory. Press F5 or choose Start from the Run menu to run the application.


Booksale Sample Application
Booksale Sample Application (BOOK_CLI.VBP and BOOK_SVR.VBP), Enterprise Edition

This project demonstrates the use of an OLE server to encapsulate the logic of business policies and rules and to provide black box services to an external User Interface component.  The client project is dedicated to delivering a clear and intuitive user interface for the user to select control options and view processing results.  The client project cares a lot about how the user works and how they use the applications results, but it knows nothing about the business or operational rules of the application.  The server component is dedicated to encapsulating business and data access rules into "sanctioned" services that client components use to find the information they need.  The server has no idea how the user options are selected or how the results are presented to the user.  This lack of specific user knowledge helps keep the server's functionality general, and as a result should increase its reusability potential for other applications.  The server also uses class modules to structure the logic of its business and data access rules in a manner that aids development, debugging, readability, maintainability, and source code reusability.

The OLE server component can be run on the same machine as the client component, (which can be a significant aid in the development and debugging phases of a project), or it can be run on a remote machine to benefit from the distributed processing power and multi-user access features of a shared network server.  The OLE server does not need to be recompiled or changed in any way to support this location independence.

The server in this project uses a visible form purely for demonstration purposes.  There is no functional need for the server to have any UI, though state information presented through a UI can help with debugging or run-time monitoring needs.  (State monitoring requirements can  also be addressed by providing a status method on the server that can be queried by a monitor application.)

File	Description

BOOK_CLI.VBP	Client component project file.

BOOK_CLI.FRM	Client main form.

BOOK_CLI.FRX	Client main dialog graphics file.

FRMCHART.FRM	Client result chart form.

FRMCOGS.FRM	Client cost of goods form.

BOOK_CLI.BAS	Client main/global utility module.

BOOK_SVR.VBP	Server component project file.

BOOK_SVR.FRM	Server status indicator form.

BOOK_SVR.FRX	Server status indicator graphics file.

BOOK_SVR.BAS	Server main/global utility module.

SALES.CLS	Server main/public class module.

MODEL.CLS	Server private business model rule class module.

TAXES.CLS	Server private tax rule class module.

BOOKSALE.MDB	Sample Jet database file.

BOOKSALE.LDB	Sample database file created at run time by Jet.

BOOKSALE.TXT	Text file containing overview information on this sample application.

To Run

From the Visual Basic File menu, choose Open Project and select the BOOK_SVR.VBP file, which is listed in the \SAMPLES\REMAUTO\BOOKSALE subdirectory of the main Visual Basic directory. Press F5 or choose Start from the Run menu to run the server project.

Once running, this project temporarily registers its classes in the system registry. You can then start a second instance of Visual Basic to run BOOK_CLI.VBP, the user interface component that uses the class modules defined in BOOK_SVR.VBP.

Note   The OLE server can be run on the same machine as the user interface component, or it can be run on a remote machine to benefit from distributed processing power and support multi-user access.  The OLE server does not need to be recompiled or changed in any way to support this location independence.


Hello World Sample Application
Hello World Remote Automation Sample Application (HELO_SVR.VBP and HELO_CLI.VBP), Enterprise Edition

This 6-line Hello World sample demonstrates one of the simplest possible examples of Remote Automation.  The application runs on both a single machine and in a 2-machine distributed configuration without needing to be recompiled.

The server in this project uses a visible form purely for demonstration purposes.  There is no functional need for the server to have any UI, though state information presented through a UI can help with debugging or run-time monitoring needs.  (Note, state monitoring requirements could also be addressed by providing a status method on the server that could be queried by a monitor application.)

File	Description

HELO_CLI.VBP	Client component project file.

HELO_CLI.FRM 	Client main form.

HELO_SVR.VBP	Server component project file.

HELO_SVR.FRM	Server status indicator form.

HELO_SVR.BAS	Server main/global utility form.

HELO_SVR.CLS	Server class module.

To Run

From the Visual Basic File menu, choose Open Project and select the HELO_SVR.VBP file, which is listed in the \SAMPLES\REMAUTO\HELLO subdirectory of the main Visual Basic directory. Press F5 or choose Start from the Run menu to run the server project.

Once running, this project temporarily registers its classes in the system registry. You can then start a second instance of Visual Basic to run HELO_CLI.VBP, the client that uses the class modules defined in HELO_SVR.VBP.

Note   The OLE server can be run on the same machine as the client, or it can be run on a remote machine to benefit from distributed processing power and support multi-user access.  The OLE server does not need to be recompiled or changed in any way to support this location independence.


Interface Sample Application
Interface Sample Application (INTR_SVR.VBP and INTR_CLI.VBP), Enterprise Edition

This sample demonstrates a way to get around OLE's "apartment model" resource allocation algorithm when the context of an entire project needs to be preserved for a specific client.

The server in this project does not have a form module, and as such, will not be visible on the machine it is running on.  (When a client has an active reference to it, however, it can be seen in the running task list.)

File	Description

INTR_CLI.VBP	Client component project file.

INTR_CLI.FRM	Client main form.

INTR_SVR.VBP	Server component project file.

INTR_SVR.BAS	Server main/global utility module.

INTR_SVR.CLS	A public interface class module that clients use to access the private classes of this component.

GETDATE.CLS	A private class that returns the current date.

GETTIME.CLS	A private class that returns the current time.

INTRFACE.TXT	A text file with a project overview and description.

To Run

From the Visual Basic File menu, choose Open Project and select the INTR_SVR.VBP file, which is listed in the \SAMPLES\REMAUTO\INTRFACE subdirectory of the main Visual Basic directory. Press F5 or choose Start from the Run menu to run the server project.

Once running, this project temporarily registers its classes in the system registry. You can then start a second instance of Visual Basic to run INTR_CLI.VBP, the client that uses the class modules defined in INTR_SVR.VBP.

Note   The OLE server can be run on the same machine as the client, or it can be run on a remote machine to benefit from distributed processing power and support multi-user access.  The OLE server does not need to be recompiled or changed in any way to support this location independence.


Passthrough Sample Application
Passthrough Server Sample Application (PASS_SVR.VBP and PASS_CLI.VBP), Enterprise Edition

This sample application is an example of a simple pass-through server.  It has one method called RunServer, which takes a ProgID parameter of the server that is to be started.  The server specified by the ProgID is run on the same machine that the pass-through server is running on.  If the server specified by ProgID is an in-process server, it is run in the same process space as the pass-through server.

RunServer returns the handle of the started server so that the client can talk directly to the requested server.  Because the pass-through server is a single-use server, every client that uses it will get its own instance of the pass-through server, along with its own process space and thread of execution.

By using the pass-through server, client applications can create their own independent execution context on a remote server and then start and stop in-process servers within that context as needed.  Because in-process servers can be started very quickly and because they are run within the pass-through server's process space, this is a much more efficient execution model than solely using out-of-process servers.

The server in this project uses a visible form purely for demonstration purposes.  There is no functional need for the server to have any UI, though state information presented through a UI can help with debugging or run-time monitoring needs.  (State monitoring requirements can also be addressed by providing a status method on the server that can be queried by a monitor application.)

File	Description

PASS_CLI.VBP	Client component project file.

PASS_CLI.FRM 	Client main form.

PASS_SVR.VBP	Server component project file.

PASS_SVR.FRM	Server status indicator form.

PASS_SVR.BAS	Server main/global utility module.

PASS_SVR.CLS	Server class module.

PASSTHRU.TXT	A text file containing a project overview and description.

To Run

From the Visual Basic File menu, choose Open Project and select the PASS_SVR.VBP file, which is listed in the \SAMPLES\REMAUTO\PASSTHRU subdirectory of the main Visual Basic directory. Press F5 or choose Start from the Run menu to run the server project.

Once running, this project temporarily registers its classes in the system registry. You can then start a second instance of Visual Basic to run PASS_CLI.VBP, the client that uses the class modules defined in PASS_SVR.VBP.

Note   The OLE server can be run on the same machine as the client, or it can be run on a remote machine to benefit from distributed processing power and support multi-user access.  The OLE server does not need to be recompiled or changed in any way to support this location independence.


Pool Manager Sample Application
Pool Manager Sample Application (PMGR_SVR.VBP and PMGR_CLI.VBP), Enterprise Edition

This sample app is an example of a simple pool manager that could be used to maintain open instances of OLE servers for client applications.  Using this scheme, client applications ask the pool manager for a pointer to an object they want to use.  The pool manager checks the pool, and either grants or denies the request.  This approach has a number of benefits:

It avoids the lengthy OLE server creation costs associated with each client request.  This is because the pool is typically created before a client needs a server.

Based on the frequency of client requests, the potential number of clients, and the duration of server tasks, a pool size can be created (or even adjusted as demand dictates at various times) that is significantly smaller than a one-to-one allocation scheme for clients and servers.  For example: if the number of clients is 60, the average frequency of requests is one per minute per client, and the average duration of a server task is one second.  A linear allocation plan would suggest that one server is needed to meet the needs of 60 clients.  Realistically, requests will not be perfectly spaced; therefore, a reasonable level of redundancy, for instance a pool size of 5 OLE servers, could be used to meet the normal needs of the 60 clients.

It limits the number of servers that can be created of a specific type to a threshold that has been determined by the server administrator.  This can be a very useful tuning parameter, and can also be useful in preventing the server from being abused by a peak request of a low priority server.

The server in this project uses a visible form purely for demonstration purposes.  There is no functional need for the server to have any UI, though state information presented through a UI can help with debugging or run-time monitoring needs.  (State monitoring requirements can also be addressed by providing a status method on the server that can be queried by a monitor application.)

File	Description

PMGR_CLI.VBP	Client component project file.

PMGR_CLI.FRM 	Client main form.

PMGR_SVR.VBP	Server component project file.

PMGR_SVR.FRM	Server status indicator form.

PMGR_SVR.BAS	Server main/global utility module.

PMGR_SVR.CLS	Server class module.

POOLMNGR.TXT	A text file containing a project overview and description.

To Run

From the Visual Basic File menu, choose Open Project and select the PMGR_SVR.VBP file, which is listed in the \SAMPLES\REMAUTO\POOLMGR subdirectory of the main Visual Basic directory. Press F5 or choose Start from the Run menu to run the server project.

Once running, this project temporarily registers its classes in the system registry. You can then start a second instance of Visual Basic to run PMGR_CLI.VBP, the client that uses the class modules defined in PMGR_SVR.VBP.

Note   The OLE server can be run on the same machine as the client, or it can be run on a remote machine to benefit from distributed processing power and support multi-user access.  The OLE server does not need to be recompiled or changed in any way to support this location independence.


Callback Sample Application
Callback Sample Application (CLBK_SVR.VBP and CLBK_CLI.VBP), Enterprise Edition

This sample demonstrates the use of an OLE object pointer being passed to an external (and optionally remote) OLE server.  The OLE server then periodically calls a method on this object pointer. This has the effect of a server-initiated callback to the client, which can be a much better application model than the polling a client application might have to do otherwise to find the status of a server.  Although this demo simply returns the time to the client, it could just as easily return data, news, or other information it has been told the client wants to know.  The benefit here is that the server does all the work looking for data the client might need and the client does other work, only being interrupted when the server actually has something that interests it.

The server in this project uses a visible form purely for demonstration purposes.  There is no functional need for the server to have any UI, though state information presented through a UI can help with debugging or run-time monitoring needs.  (Note, state monitoring requirements could also be addressed by providing a status method on the server that could be queried by a monitor application.)

File	Description

CLBK_CLI.VBP	Client component project file.

CLBK_CLI.FRM	Client main form.

CLBK_CLI.BAS	Client main/global utility module.

CLBK_CLI.CLS	Client class module.

CLBK_SVR.VBP	Server component project file.

CLBK_SVR.FRM	Server status indicator form.

CLBK_SVR.BAS	Server main/global utility module.

CLBK_SVR.CLS	Server class module.

CALLBACK.TXT	A text file containing a project overview and description.

To Run

From the Visual Basic File menu, choose Open Project and select the CLBK_SVR.VBP file, which is listed in the \SAMPLES\REMAUTO\CALLBACK subdirectory of the main Visual Basic directory. Press F5 or choose Start from the Run menu to run the server project.

Once running, this project temporarily registers its classes in the system registry. You can then start a second instance of Visual Basic to run CLBK_CLI.VBP, the client that uses the class modules defined in CLBK_SVR.VBP.

Note   The OLE server can be run on the same machine as the client, or it can be run on a remote machine to benefit from distributed processing power and support multi-user access.  The OLE server does not need to be recompiled or changed in any way to support this location independence.


Jet/DAO Sample Application
Jet/DAO Sample Application (JET1_SVR.VBP and JET1_CLI.VBP), Enterprise Edition

This sample demonstrates the use of Jet/DAO to access a remote database through an independent, OLE-based, data access object. DAO (short for Data Access Object) is a rich and fairly high-level programming interface that has many features to help simplify data access programming tasks.  However, its use can significantly increase the amount of memory a server needs and therefore may be limited in its ability to address the needs of remote server scenarios that are either performance-intensive or that support many concurrent users.  See the Guide to Data Access Objects for more information on DAO.

By placing data access code into a separate component in this manner, data access details can be hidden from client components, thus making client component development easier and providing more independence to database administrators.  In many cases, deploying data access server objects on the same machine as the database engine can greatly reduce network traffic and improve overall data request throughput speed.  Because this object uses an ODBC interface to connect to a back-end database, it can be run from either a client machine or a server machine without modification.  (Both machines simply need to have the same ODBC driver and DSN connection name registered on their machines.)

The server in this project uses a visible form purely for demonstration purposes.  There is no functional need for the server to have any UI, though state information presented through a UI can help with debugging or run-time monitoring needs.  (State monitoring requirements can also be addressed by providing a status method on the server that can be queried by a monitor application.)

File	Description

JET1_CLI.VBP	Client component project file.

JET1_CLI.FRM 	Client main form.

JET1_SVR.VBP	Server component project file.

JET1_SVR.FRM	Server status indicator form.

JET1_SVR.BAS	Server main/global utility module.

JET1_SVR.CLS	Server class module.

To Run

From the Visual Basic File menu, choose Open Project and select the JET1_SVR.VBP file, which is listed in the \SAMPLES\REMAUTO\DB_JET subdirectory of the main Visual Basic directory. Press F5 or choose Start from the Run menu to run the server project.

Once running, this project temporarily registers its classes in the system registry. You can then start a second instance of Visual Basic to run JET1_CLI.VBP, the client that uses the class modules defined in JET1_SVR.VBP.

Note   The OLE server can be run on the same machine as the client, or it can be run on a remote machine to benefit from distributed processing power and support multi-user access.  The OLE server does not need to be recompiled or changed in any way to support this location independence.


ODBC Sample Application
ODBC Sample Application (ODBC_SVR.VBP and ODBC_CLI.VBP), Enterprise Edition

This sample demonstrates the use of ODBC to access a remote database through an independent, OLE-based, data access object.  ODBC is a low-level API interface that is more complicated than most other data access options, but requires a minimal amount of memory to run and can be very fast if used well.  See Chapter 12, "Using the ODBC API," of Building Client/Server Applications with Visual Basic for more information on the use of ODBC.

By placing data access code into a separate component in this manner, data access details can be hidden from client components, thus making client component development easier and providing more independence to database administrators.  In many cases, deploying data access server objects on the same machine as the database engine can greatly reduce network traffic and improve overall data request throughput speed.  Because this object uses an ODBC interface to connect to a back-end database, it can be run from either a client machine or a server machine without modification.  (Both machines simply need to have the same ODBC driver and DSN connection name registered on their machines.)

The server in this project uses a visible form purely for demonstration purposes.  There is no functional need for the server to have any UI, though state information presented through a UI can help with debugging or run-time monitoring needs.  (State monitoring requirements can also be addressed by providing a status method on the server that can be queried by a monitor application.)

File	Description

ODBC_CLI.VBP	Client component project file.

ODB1_CLI.FRM	Client main form.

ODBC_SVR.VBP	Server component project file.

ODB1_SVR.FRM	Server status indicator form.

ODB1_SVR.BAS	Server main/global utility module.

ODB1_SVR.CLS	Server class module.

ODBC16.TXT	16-bit ODBC API Declare statements.

ODBC32.TXT	32-bit ODBC API Declare statements.

To Run

From the Visual Basic File menu, choose Open Project and select the ODBC_SVR.VBP file, which is listed in the \SAMPLES\REMAUTO\DB_ODBC subdirectory of the main Visual Basic directory. Press F5 or choose Start from the Run menu to run the server project.

Once running, this project temporarily registers its classes in the system registry. You can then start a second instance of Visual Basic to run ODBC_CLI.VBP, the client that uses the class modules defined in ODBC_SVR.VBP.

Note   The OLE server can be run on the same machine as the client, or it can be run on a remote machine to benefit from distributed processing power and support multi-user access.  The OLE server does not need to be recompiled or changed in any way to support this location independence.


Remote Data Object (RDO) Sample Application
Remote Data Object (RDO) Sample Application (RDO_SVR.VBP and RDO_CLI.VBP), Enterprise Edition

This sample demonstrates the use of Remote Data Objects (RDO) to access a remote database through an independent, OLE-based, data access object. RDO is a rich and fairly high-level programming interface that has many features to help simplify data access programming tasks.  RDO also has been built specifically for remote data access requirements, and as such,  can be a very good option for quickly building server components that must meet high performance and high concurrent user requirements.

By placing data access code into a separate component in this manner, data access details can be hidden from client components, thus making client component development easier and providing more independence to database administrators.  In many cases, deploying data access server objects on the same machine as the database engine can greatly reduce network traffic and improve overall data request throughput speed.  Because this object uses an ODBC interface to connect to a backend database, it can be run from either a client machine or a server machine without modification.  (Both machines simply need to have the same ODBC driver and DSN connection name registered on their machines.)

The server in this project uses a visible form purely for demonstration purposes.  There is no functional need for the server to have any UI, though state information presented through a UI can help with debugging or run-time monitoring needs.  (State monitoring requirements can also be addressed by providing a status method on the server that can be queried by a monitor application.)

File	Description

RDO_CLI.VBP	Client component project file.

RDO_CLI.FRM	Client main form.

RDO_SVR.VBP	Server component project file.

RDO_SVR.FRM	Server status indicator form.

RDO_SVR.BAS	Server main/global utility module.

RDO_SVR.CLS	Server class module.

DB_RDO.TXT 	A text file containing a project overview and description.

To Run

From the Visual Basic File menu, choose Open Project and select the RDO_SVR.VBP file, which is listed in the \SAMPLES\REMAUTO\DB_RDO subdirectory of the main Visual Basic directory. Press F5 or choose Start from the Run menu to run the server project.

Once running, this project temporarily registers its classes in the system registry. You can then start a second instance of Visual Basic to run RDO_CLI.VBP, the client that uses the class modules defined in RDO_SVR.VBP.

Note   The OLE server can be run on the same machine as the client, or it can be run on a remote machine to benefit from distributed processing power and support multi-user access.  The OLE server does not need to be recompiled or changed in any way to support this location independence.