To create a new 32-bit Visual Basic 4.0 project that uses the DB-Library for Visual Basic OLE custom control, follow these steps, which are fully outlined in the following text:
The Custom Controls dialog box appears.
The Add Custom Control dialog box appears.
The Available Controls list now includes "Vbsql OLE Custom Control module," and it is selected.
The DB-Library for Visual Basic OLE custom control is now included in the Toolbox. Its tooltip is "Vbsql."
The Add File dialog box appears.
The Project window now includes the VBSQL.BAS module. Visual Basic will automatically generate a unique name for this module. For a new project, the default name for this module will be "Module1."
It is recommended that you not change the VBSQL.BAS header file. If you use the Visual Basic Code window to edit the VBSQL.BAS header file, Visual Basic will add a line to the top of the file similar to the following:
Attribute VB_Name = "Module1"
The Visual Basic Code window does not display this line. After this line has been added, Visual Basic will use the specified module name, and will not automatically generate a unique name. If your project already includes a module with the same name as the modified VBSQL.BAS header file, attempting to add it will generate the following error:
Name conflicts with existing module, project, or object library
If you must change the VBSQL.BAS header file, use either Notepad (or other text editor that will not add the VB_Name line to the file), or make a copy of the VBSQL.BAS header file and include that copy in your project.
The pointer becomes a cross hair.
The control will be called "Vbsql1" by default.
Add one and only one control to a single form in your project, and always keep that form loaded. Do not add the DB-Library for Visual Basic OLE custom control to more than one form, and do not unload the form that contains the control.
The DB-Library for Visual Basic OLE custom control has two custom event procedures:
Event | Occurs |
---|---|
Error | When a DB-Library error occurs |
Message | When a SQL Server message is received |
The Visual Basic Code window appears.
The Error event procedure has the following syntax:
Private Sub Vbsql1_Error (
ByVal SqlConn As Long,
ByVal Severity As Long,
ByVal ErrorNum As Long,
ByVal ErrorStr As String,
ByVal OSErrorNum As Long,
ByVal OSErrorStr As String,
RetCode As Long )
The OSErrorNum and OSErrorStr parameters are new with the DB-Library for Visual Basic OLE custom control, and they match the parameters that are available with DB-Library for C.
The Message event procedure has the following syntax:
Private Sub Vbsql1_Message (
ByVal SqlConn As Long,
ByVal Message As Long,
ByVal State As Long,
ByVal Severity As Long,
ByVal MsgStr As String,
ByVal ServerNameStr As String,
ByVal ProcNameStr As String,
ByVal Line As Long )
The ServerNameStr, ProcNameStr, and Line parameters are new with the DB-Library for Visual Basic OLE custom control, and they match the parameters that are available with DB-Library for C.
Note that Visual Basic will create a VBSQL.OCA file, usually in the same directory as VBSQL.OCX. Visual Basic stores cached-type library information (and other data that is specific to the custom control) in the VBSQL.OCA file and re-creates it as needed.
For more information about managing Visual Basic projects, see the Microsoft Visual Basic 4.0 Programmer's Guide.