Lesson 1: Creating a Data Browser
Show this topic in Library frames
This section steps you through the process of creating a form that enables users to browse student information. It shows you how to incorporate Pervasive's ActiveX data source and bound controls into a new Visual Basic project. After this lesson, you will be able to perform the following tasks:
Adding Pervasive's ActiveX Interface to a VB Project
To begin building the application, run Visual Basic and begin a new STANDARD.EXE project.
The first step in using Pervasive's ActiveX interface is to add the ActiveX control components to a Visual Basic project. The components consist of two files-ACBTR732.OCX (Pervasive.SQL ActiveX Data Source) and ACCTR732.OCX (Pervasive.SQL Bound Controls).
To add Pervasive's ActiveX interface to a Visual Basic Project:
- Select Components from the Project menu (or right-click in the Toolbox and select Components).
- Scroll through the Controls list and select Pervasive ActiveX Data Source and Pervasive Bound Controls check boxes.
- Click OK.

The Pervasive ActiveX icons appear in the Toolbox.
Creating a VAccess Control Form
After adding Pervasive's ActiveX interface to a new project, use the Properties window to name the first form.
To name the form:
- For the Name property, use frmVAccessForm.
- For the Caption property, use VAccess Form.
The next step in building the application is placing a VAccess control on the form. The VAccess control is the master control which points to your data and to which all other Pervasive.SQL controls are bound. It handles all communication with Pervasive.SQL.
To add the VAccess control to your Visual Basic form:
- Click the Visual Basic Toolbox containing the Pervasive.SQL ActiveX interface.
- Left-click the mouse on the VAccess control's icon.

- Put your cursor on the form and drag to create a rectangle to hold the control. When you release the mouse, the ActiveX control appears in the rectangle.
You also may notice the Pervasive.SQL splash screen indicating that the Pervasive.SQL database engine has been started. The control is visible at design time as an icon, but is invisible at run time.
- Leave the default name of this VAccess control as VAccess1.
You will place all of the project's VAccess controls on this same form, separate from the bound controls. The advantage of placing the VAccess controls on their own form is two-fold:
- At design time, data controls can accept binding or joining from other controls only if the form on which the data control sits is visible. (This is not the case at run time.)
- All data controls must have a unique name regardless of what form they are on. Keeping them all on one form allows Visual Basic to warn you if you are giving a control the same name as an existing control.
- If your project grows, you will want all data controls in one form.
Setting Properties in Pervasive's ActiveX interface
Before continuing with the tutorial, this section includes an explanation of how to set the Pervasive.SQL ActiveX properties. The properties can be set in one of three places:
- Property Pages dialog box
- Visual Basic Properties window
- Visual Basic Code Editor
Property Pages
This is a tabbed dialog box available when you right-click on the control and choose Properties from the pop-up menu. These are the custom properties for the control and concern the connection to your data. Throughout this tutorial, you will mostly use the Property Pages dialog box.
Figure 6-1-Property Pages Dialog Box
Visual Basic Properties Window
The window displays the complete set of properties for the selected object.
Figure 6-2-Visual Basic Properties Window
Visual Basic Code Editor
Refer to the ActiveX Interface for Pervasive.SQL User's Guide and Reference Manual for details about each property.
You will set these properties in the following sections of the tutorial.
Connecting to a Pervasive.SQL File
There are three important properties of the VAccess control that connect it to a Pervasive.SQL file: DdfPath, TableName, and Location. The easiest way to access these properties is through the Property Pages, available when you right-click on the control and choose Properties from the pop up menu. You can also access them through the Properties window if you prefer.
Figure 6-3-Setting Properties to Connect to Your Data
The three important properties that connect to your data are as follows:
- DdfPath-This property determines the location of the DDFs (Data Dictionary Files) which will be used by the VAccess Control. This property must contain a valid drive and path where DDFs are located.
- TableName-This property determines which table information from the DDFs will be used by the VAccess control. This property must be set to a valid table name contained in the DDFs specified in the DdfPath. You can select the table name from the drop down menu.
- Location-This property determines which Pervasive.SQL data file will be used by the VAccess control. It corresponds to the Table Location contained in FILE.DDF. The default for this property is the Table Location for the table specified in the TableName property, but you can give an alternate path to the data file if you wish.
To set the properties pointing to your data:
- See that the DdfPath of the VAccess1 control is set by default to c:\PVSW\DEMODATA. (This setting is read from the Registry.)
- From the TableName property's drop-down menu containing the tables available in the DDFs, select Student as the TableName.
All Pervasive.SQL bound controls will now refer to this table when they are bound to this VAccess control. As you select Student, the Location property changes to the STUDENT.MKD file.
The three file location properties should now be set as follows:
|
Property
|
Value
|
|
DdfPath
|
c:\PVSW\DEMODATA
|
|
TableName
|
Student
|
|
Location
|
c:\PVSW\DEMODATA\STUDENT.MKD
|
Now you must set the index number.
To set the index number of your table:
- Go to the Settings tab of the VAccess1 Property Pages dialog box and click the IndexNumber field to see the list of indexes that have been defined for the Student table.
- Choose index 0 - ID and click OK. The settings are shown in Figure 6-4-.
Figure 6-4-Setting the IndexNumber Property

Creating a Form with Bound Controls
In this section, you will learn how to place the Pervasive.SQL bound controls on a form and how to bind them to the VAccess control so that a user can browse through the database.
To set up a form with bound controls:
- Select Add Form from the Project menu.
- Click Open. (Form is the default selection.)
You will place all bound controls on separate forms from the VAccess controls as explained in the previous section.
- From the form's Properties window, change the new form's Name property to frmStudentBrowser and its Caption property to Pervasive.SQL Student Browser Sample Application.
Note
A convention we will follow in this tutorial is for the names of forms to begin with frm and the names of command controls to begin with cmd. This helps us distinguish forms and commands from other objects as we create our program. For the names of other controls, we will leave the defaults (such as VATextbox1, VATextbox2).
- From the Project menu, select Project Properties to open the Project Properties window. Change the Startup Object to frmStudentBrowser so that this form will be the one to appear when the application runs.
- Click OK.
Figure 6-5-Setting the Startup Form

- Now double-click on the frmStudentBrowser form to bring up the Form Load event. Enter the following code into this event:
frmVAccessForm.VAccess1.GetFirst
This code employs the GetFirst method to instruct the VAccess1 VAccess control on the frmVAccessForm to retrieve the first record. This enables the bound controls you are about to place on the form to display data when the application first runs.
Adding an Index Search
You are now ready to begin placing the bound controls on the frmStudentBrowser form. The first is a text box in which users can search the table index.
To add a text box:
- If it's not already the current form, go to the frmStudentBrowser form.
- Place a VATextBox on the form in the top left corner.

Make this box long enough to allow users to type the nine digits of student IDs.
- Right-click on the text box and select Properties to activate the text box's Property Pages.
- For the VAccessName property, select VAccess1 from the menu. This binds the VATextBox to the VAccess1 VAccess control.
- Select the VASearch check box.
This setting allows users to search the current index for a particular field. You do not need a VAFieldName because the index selected for the VAccess1 control is automatically used.
Figure 6-6-Setting the Search Index for Text Box

- Click OK.
- If you wish, place a standard Visual Basic Label control to the left of the text box and change its Caption property to:
Enter value to locate student record.
Adding a List Box
The VAListBox can be used to display single or multiple fields of information from the database in a list format.
To add a list box:

- Place a VAListBox on the form and bind it to the VAccess control by changing its VAccessName property to VAccess1.
Note
Make your list box wide enough to hold several columns of data. You will not be able to resize your columns effectively in step 5 below if the list box itself is too narrow.
- In the Property Pages dialog box, check the VARecordList check box. This sets this property to True which enables you to display fields in separate columns.
- While still in the Property Pages dialog box, double-click the ellipses button beside the VAFieldName property to display a dialog box containing the available fields.
- To set up multiple columns, double-click on an available field to select it (or click once and click on the Add button). Select the fields shown in Figure 6-7-: ID, Cumulative_GPA, Major, Minor, and Cumulative_Hours. Click OK.
Figure 6-7-Selecting the List Box Columns

- Adjust the ColumnWidth property so that the data will be displayed in orderly columns. To do this, click on the ellipses next to the ColumnWidth combo box to open the Multi-Column Tab Settings window. The first field you selected, ID, is displayed.
Note
If there is not enough room for all the columns, cancel this window and the Property Pages. Then make the list box wider and try again.
- Double-click to the right of ID to set the first tab stop. A hashed line appears. Drag this line to provide enough space for the data that will be displayed in this column. Continue double-clicking and dragging these lines until you have displayed and adjusted the tabs for the four columns.
- When you are finished, the window should look similar to the one in Figure 6-8-. Click OK in this window and then click OK in the Property Pages to finalize your changes.
Figure 6-8-Sizing the List Box Columns

- Place five Visual Basic Label controls on the form above the VAListBox to label each of the columns. Use the captions ID, Cumulative_GPA, Major, Minor, and Cumulative_Hours.
Adding a Vertical Scroll Bar
The VAVScrollBar allows users to quickly navigate through the database.
To add a vertical scroll bar:
- Place a VAVScrollBar on the form, shaping it as a vertical scroll bar and aligning it with the right side of the VAListBox.
- Set the scroll bar's VAccessName property to VAccess1 to bind it to the VAccess control.
Adding a Visual Basic Command Button
You can use Visual Basic command buttons so the user can bring up the other forms described later in this tutorial.
To add a VB command button:
- Place two Visual Basic command buttons at the bottom of the form.
- Change the Name property of one button to cmdUpdate and the other to cmdBrowse.
- Change the Caption property of one button to Update Student Data and the other to Browse Personal Data. You will add code to these later in the tutorial to make them functional.
Your form should be similar to the one in Figure 6-9-.
Figure 6-9-Student Browser Before Running

Testing the Application
To test your application at this point:
- First, save your work using the File menu's Save Project As option.
- Select Start from the Run menu.
The VATextBox and VAListBox are synchronized so that if you type a student ID into the text box, it will appear at the top of the list box. You can also use the VAVScrollBar to scroll through the database.
You will probably need to adjust the size of the VAListBox, the position of the column label controls, or the position of the tabs in the ColumnWidth property to make the form design consistent. Your compiled sample browser should resemble Figure 6-10-.
Figure 6-10-Student Browser After Running
