Porting an Old DB-Library for Visual Basic Project

To port a Visual Basic 3.0 project that uses the old 16-bit DB-Library for Visual Basic VBSQL.VBX to a Visual Basic 4.0 project that uses the new 32-bit DB-Library for Visual Basic OLE custom control VBSQL.OCX, follow these steps:

  1. Open the 16-bit project using Visual Basic 4.0.
  2. You will receive messages similar to the following:
    Can't load (or register) custom control: 'C:\SQL60\BIN\VBSQL.VBX' -- 
    Continue loading project?
      
    Custom control 'VBX.VBSQL' not found
      
    Error loading 'C:\CODE\MAIN.FRM'. A control could not be loaded due 
    to load error. Continue?
      

    In each case, choose the Yes or OK button.

  3. If you added the old DB-Library for Visual Basic header file (VBSQL.BAS or VBSQL.BI) directly to your Visual Basic 3.0 project, you might receive a message similar to the following:
    File not found: 'C:\SQL60\DBLIB\INCLUDE\VBSQL.BAS' -- Continue 
    loading project?
      

    This message indicates that Visual Basic could not find a VBSQL.BAS header file in the specified location. Add the new VBSQL.BAS header file to your project.

    If you do not receive this message, Visual Basic found a VBSQL.BAS header file at the location specified in your old project. Ensure that it is the new VBSQL.BAS header file. If it is the old VBSQL.BAS header file, remove the old one, and then add the new VBSQL.BAS header file to your project.

  4. If you pasted the contents of the old VBSQL.BAS header file into a separate .BAS file of your Visual Basic 3.0 project, remove the old header file contents from the separate .BAS file, and then add the new VBSQL.BAS header file to your project.
  5. The old VBSQL.VBX custom control will still be placed on a form in your project, probably as a red PictureBox control. Remove the old control from the form.

    Visual Basic will place your old error handling and message handling event procedures in the list of general procedures for the form. These event procedures will be named control_Error and control_Message, where control is the name of the old VBSQL.VBX custom control, for example "VBSQL1."

  6. Add the new DB-Library for Visual Basic OLE custom control (VBSQL.OCX) to a form in your project.
  7. Copy the code from the old error handling and message handling procedures (now listed as general procedures) to the Error and Message event procedures of the new DB-Library for Visual Basic OLE custom control.

    Both the Error and Message event procedures have new parameters, but the existing parameters have the same names, so the old code should work unchanged.

  8. Change all Integer values (%) used by DB-Library for Visual Basic to Long (&) values. This includes DB-Library function names (if % was used), parameters passed to DB-Library functions, and values returned by DB-Library functions.

    In all of the following examples, bold text indicates the code changes you must make. For brevity, checking of return codes is not included.

    For example, if your old Visual Basic project includes the following DB-Library code:

    Dim LoginRec As Integer
    Dim SqlConn As Integer
    Dim Return As Integer
    Dim SqlCommand As String
      
    LoginRec = SqlLogin
    ' Fill in LoginRec
    SqlConn = SqlOpen(LoginRec, "gizmo")
    Return = SqlUse(SqlConn, "pubs")
    SqlCommand = "select au_fname from authors"
    Return = SqlCmd(SqlConn, SqlCommand)
    Return = SqlExec(SqlConn)
      

    then the new code needs only the following changes:

    Dim LoginRec As Long
    Dim SqlConn As Long
    Dim Return As Long
    Dim SqlCommand As String
      
    LoginRec = SqlLogin
    ' Fill in LoginRec
    SqlConn = SqlOpen(LoginRec, "gizmo")
    Return = SqlUse(SqlConn, "pubs")
    SqlCommand = "select au_fname from authors"
    Return = SqlCmd(SqlConn, SqlCommand)
    Return = SqlExec(SqlConn)
      

    However, if your old Visual Basic project includes the following DB-Library code using the Integer datatype specifier (%):

    LoginRec% = SqlLogin%
    ' Fill in LoginRec
    SqlConn% = SqlOpen%(LoginRec%, "gizmo")
    Return% = SqlUse%(SqlConn%, "pubs")
    SqlCommand$ = "select au_fname from authors"
    Return% = SqlCmd%(SqlConn%, SqlCommand$)
    Return% = SqlExec%(SqlConn%)
      

    then the new code can be changed to the following, using the Long datatype specifier (&) for DB-Library functions, parameters, and return values:

    LoginRec& = SqlLogin&
    ' Fill in LoginRec
    SqlConn& = SqlOpen&(LoginRec&, "gizmo")
    Return& = SqlUse&(SqlConn&, "pubs")
    SqlCommand$ = "select au_fname from authors"
    Return& = SqlCmd&(SqlConn&, SqlCommand$)
    Return& = SqlExec&(SqlConn&)
      

    Because the datatype specifiers are not required for DB-Library function names, you can change the new code to the following:

    LoginRec& = SqlLogin
    ' Fill in LoginRec
    SqlConn& = SqlOpen(LoginRec&, "gizmo")
    Return& = SqlUse(SqlConn&, "pubs")
    SqlCommand$ = "select au_fname from authors"
    Return& = SqlCmd(SqlConn&, SqlCommand$)
    Return& = SqlExec(SqlConn&)
      

    You can also take this opportunity to change your code to use Dim to explicitly declare your variables, thus removing the Long specifier (&) from each variable.

    If you forget to make a required change from Integer to Long, Visual Basic will generate the following error when you run the program:

    Type-declaration character does not match declared data type
      

    and the Visual Basic debugger will highlight the DB-Library function, parameter, or variable (for example, the SqlSetLoginTime% function or a SqlConn% variable) that is causing the error.