Using the Connectivity Kit to Connect to ASCII Text Files

ID: Q116079

2.50 2.50a 2.50b 2.60 WINDOWS kbinterop

The information in this article applies to:

SUMMARY

This article describes how to use the FoxPro Connectivity Kit and ODBC to access data that resides in an ASCII text file.

MORE INFORMATION

This article assumes that you have the Text ODBC driver that is available as a part of the Microsoft ODBC Desktop Database Driver Kit (DDDK). This driver is also included with some Microsoft products, such as Microsoft Word for Windows and Microsoft Excel for Windows.

Support for drivers that are included in the DDDK but not shipped with FoxPro is provided by the Microsoft Advanced Systems group at:

To connect to a Text data source, you must install the Text ODBC Driver and set up a Text data source through the ODBC Text Setup dialog box in the Windows Control Panel. Since this is a level 1 ODBC driver, the data source is a directory name or the current directory, as indicated in the Setup dialog box. The Options dialog box in the Text Driver Setup provides users with the ability to select and define various text formats, such as comma-separated values (CSV), tab delimited, and so on.

The following is a code sample that "connects" to a Text data source:

   *-- Connect to a Text Data Source
   PRIVATE lcSource, lcUser, lcPwd, hDBHdle, lnDBRes

   *-- Init memvars
   STORE 0 TO hDBHdle, lnDBRes
   lcSource = "Text"      && Text Data Source Name from ODBC Dialog
   lcUser = ""            && Not needed for single-tier drivers
   lcPwd = ""             && Not needed for Text

   *-- Load Library if not already
   IF !"FPSQL" $ SET('library')
        SET LIBRARY TO FPSQL.FLL
   ENDIF
   WAIT WINDOW "Attempting connection ..." NOWAIT
   hDBHdle = dbConnect(lcSource, lcUser, lcPwd, "")
   IF hDBHdle > 0
      WAIT WINDOW ;
    "Connected to Text File -  Handle:"+STR(hDBHdle,1,0) TIMEOUT 2
   ELSE
      WAIT WINDOW ;
    "Unable to connect to Text File .."
   ENDIF

   * If the Text data source does not point to a specific directory
   * (Use Current Directory is checked in Setup dialog box), the
   * following DBExec() will place the user in the desired directory:

   lnDbRes = DBExec(hDBHdle, "USE f:\smpldata\text\csv")
   *(change drive and directory to suit)

   * The Text ODBC driver can be useful in the many situations where
   * PC users need to interact with various forms of ASCII data.

   * The following example creates a cursor in FoxPro containing the
   * drivers in the SYSTEM.INI file:

   lnDbRes = ;
     DBExec(hDBHdle, "use c:\wfw31.466")  && Select desired directory
   lnDbRes = ;
     DBExec(hDBHdle, ;
     "select * from system.ini where field_1 like 'device=%'")

REFERENCES

Microsoft ODBC Desktop Database Driver Kit Text Driver online Help file

Additional reference words: FoxWin 2.50 2.50a 2.50b 2.60 ck KBCategory: kbinterop KBSubcategory: FxtoolCk

Keywords          : kbcode FxtoolCk 
Version           : 2.50 2.50a 2.50b 2.60
Platform          : WINDOWS

Last Reviewed: January 8, 1999