Airfield Models - Visual Basic Database

December 19, 2021



Home
About
Site Feedback
Register
Contact
Site Map
Add to Favorites
Comments
Search Airfield Models

Back to VB DB

 

Airfield Models (http://www.airfieldmodels.com/)VB DB Quick Start Guide

The Quick start guide is intended for experienced VB programmers.  If you are new to programming or have limited experience, then click here for tutorials.

Download VB DB Source Code here.

 
 

VB DB Specific Code

You most likely already have your own pet routines for checking things like the existence of a file, etc.  You can move just the VB DB specific modules to your app and make modifications to use your own utility functions.

For example, you can move the error codes in bApplicationErrorhandler.bas to your own error handler.  However, it will be easiest if you use a conversion of VB DB to solidify your file handling before porting code to your app.

 
 

Quick Start

All the necessary modifications to the code directly relate to the fields you want to save in a file.

The field names are defined in the FIELD_INDEX Enum in the bVBDB.bas module.  The field names will appear in quick tips within code windows.

Important!  Change the last Enum entry (FIELD_INDEX_MAX) to equal the LAST field you create in the FIELD_INDEX Enum.

Next, define the field definitions (data type, displayed field name, required, etc.) In the CreateDataFields sub-routine in the cTable.cls class module.  The source code includes examples for most data types and an array field.

' cTable.cls

Private Sub CreateDataFields()

' ***** MODIFY *****

' Before creating fields, modify the FIELD_INDEX Enum in bVBDB.bas.
' Use the values from the Enum as subscripts for your fields

' Note: You can assign the Constant CurrentDateTime (-1) to a date field
' if you want the value Now() to be used as the default.

With m_FieldDefinitions(FIELD_01)
  .ArrayField = False ' Is this field an array?
  .DataType = dataBoolean ' Specify a field data type
  .DefaultValue = False ' Value entered when a new record is created
  .FieldName = "Boolean 1"  ' The name displayed to the user
  .Index = NewFieldIndex ' The next available index
  .Required = False ' Is data required?
  .RequireUniqueEntry = False ' Must data be unique from other records?
  .SystemField = False ' Is this a system field?
End With

' Code for remaining fields not shown for brevity

' ***** END MODIFY *****

End Sub

The tFieldDefinitions Type defines various field properties as follows:

Index Unique index for the field
SystemField System fields should not be changed in any way.  Doing so will require you to edit a lot of code.
FieldName A string identifier for each field.  This is generally the field name displayed to the user.  The name does not have to be unique, but it should be.
ArrayField Informs VB DB that the field you have created should be treated as an array rather than a normal variable.
DataType VB DB will validate data against the Data type you specify for the field.  Note: All fields are actually stored as variants.
DefaultValue The value initially entered into the field when a new record is created.
Required Informs VB DB that there must be a value in this field.  For dates and numbers, the data entered can not be Null.  For strings, the data can not be an empty string.
RequireUniqueEntry If true, then a value in a field can not be duplicated in another record.  For strings, the comparison is not case-sensitive.

Note:  VB DB does not support adding additional fields after a file has been created but most field properties can be changed using the Field Properties dialog in the Records menu.

After adding controls for the fields you have created, be sure to add the following line of code to the Changed Event for TextBoxes and the Click Event for CheckBoxes:

Changed = True

The fields you create are indexed to the lblField labels.  The name you assign to the first FIELD_INDEX enum you create (not the "system" fields) will be the caption for lblField(0).  The rest of the lblField(x) labels are indexed in the same order as the enum.

Now the fun begins!  You can either look for places that need the code to be modified (' ***** MODIFY *****) or do what I do use CTRL + F5 and let VB show you where you need to change the code.  VB DB has been made as generic as possible, but you still need to modify the code so the controls display data from the proper fields.  Please do not try to take shortcuts and use Replace All here.  You may inadvertently rename something you shouldn’t and have a debugging nightmare!

If you are not using an Array for any of the fields, you can delete all the code having to do with a field array.  If you need more than one array, just copy the existing code and make additional subroutines for each array.  I plan to make the array fields even more generic at some point so you won't need to do this.  But for now it's necessary.

In the Validate Function of frmDatabase.frm, add any additional data validation you want to use.  VB DB will make sure the data entered into a field is of the correct data type, but that's as far as it goes.  For example, if you want dates to be entered within a certain range, you will have to add the necessary code.

 
 

Finished

When you have completed the steps above, create a new file and enter some data to ensure everything is working properly.  At this point you have the developer's version to create and manipulate your file type.  It is up to you at this point what to do with it.

Make a copy of the source code for the developer's version to convert to a distributed version.  If you want the user to be able to add, edit and delete records, then there isn't much left to do.  You may want to remove the code to let the user redefine fields, however.

On the other hand, if your file simply supplies data and is read-only, then you should strip the copy of all file-writing functionality.

 
 

Previous —
Next —

Visual Basic Database (VB DB) Source Code
VBDB Tutorials

Comments about VBDB

 
 

Back to VB DB
Airfield Models Home

 
 

Copyright © 2002-2005 Paul K. Johnson