CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: ASCII Import

  1. #1
    Join Date
    Dec 1999
    Posts
    2

    ASCII Import

    I have a VB project that I need to append records to an existing Jet table. The data comes from an ASCII comma delimited file and contains data extracted from a mini computer's database. In xBase I would use:

    USE TargetFile
    APPEND from SourceFile.txt delimited

    And I would be done. However, it is apparently not so simple in VB. I cannot use the Import Wizard in Access since this feature really needs to be embedded in the VB executable.

    Any help would be greatly appreciated!


    ***
    * J. J. Campbell
    * Alexandria, Virginia
    * Police Department
    * MailTo:[email protected]
    ***

  2. #2

    Re: ASCII Import

    I'll give you the general approach, but not all the code. I'm assuming you have VB 6.

    1. Open the text file, using the filesystemobject and a textstreamobject. Create a string variable consisting of the textstream's contents.

    2. Use the split function to Split the contents into a string array, using vbcrlf as a delimiter. Each element in the array will be a line in the file.

    (As an alternative to 1-2, you can read line by line by using the lineinput function)

    3. Loop through your array. Split each element using the split function with "," as your delimiter. You will now have a string array in which each element is a field value.

    Charlie Zimmerman
    http://www.freevbcode.com


  3. #3
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: ASCII Import

    The 'Data' Control has some support for Text files also, as records. Try the "Text" value to "Connect" property of a Data control and check if it can distinguish Comma Delimited File

    Another Round about way would be: If you have Excel installed, you can create an excel object, ask it to read the file, for this it should be named .CSV , then use that excel sheet as the data source for a data control. It works like a table, and create another Jet Db and copy all records.


    RK

  4. #4
    Join Date
    Dec 1999
    Posts
    2

    Re: ASCII Import

    Your method requires that the entire file fit in memory - I thought that was a risky assumption for my application. I found an example of what I wanted to do (or at least the part of it I didn't know how to do) on the MSDN CD-ROMs under "Connect and SourceTableName Properties Example."
    Thanks for your help.
    jj


    ***
    * J. J. Campbell
    * Alexandria, Virginia
    * Police Department
    * MailTo:[email protected]
    ***

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured