Click to See Complete Forum and Search --> : ASCII Import


JJ_Campbell
December 15th, 1999, 08:58 PM
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:jjcampbell@worldnet.att.net
***

czimmerman
December 15th, 1999, 11:55 PM
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

Ravi Kiran
December 16th, 1999, 05:56 AM
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

JJ_Campbell
December 20th, 1999, 04:46 PM
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:jjcampbell@worldnet.att.net
***