Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing null values in a text file

Status
Not open for further replies.
Jul 8, 2002
61
US
Hi Everyone,

I have a question about how to handle null values in a text file I'm importing. The txt files that get imported are fixed width. The problem is that a lot of the time these txt files have null values instead of spaces to seperate the fields. So the file would look like:

"Doe,John 10248406 20010105 45684.50**123345"
where * = null value instead of a " " (space).

When I read the txt file into an array VB doesn't seem to recognize the nulls and reads the file in like:

"Doe,John 10248406 20010105 45684.50123345"

I'm using the following code to read in each line of the txt file:
"Line Input #1, fileArray(i)"

Does anyone know how to read in a line of text dealing with null values? I think what I need to do is replace the null values with spaces, but I can't get VB to even recognize that there IS a null value. Thanks for any help!

-Andrew
 
Hmmm, maybe this will work here too. See a couple posts away "Text File Import changes text format".

Again, my suggestion is kind of a kludgy way to do it, but sometimes, its best to just get it running rather than being elegant! I had a similar situation, and the way I "fixed" it was instead of inputting a line at a time, I input the line one character at a time into an array. You could do the same thing, and if you see a null character (ASC:0), then replace it there with a space (ASC:32), then once the entire line is read, concatenate that array into a single string, now with spaces where nulls used to be.
 
Thanks gymbeef,

how can I input the file one character at a time?

Right now I'm using the "Line Input #..." method to read in the file one line at a time. What's the code to read in one character at a time?

The problem with the Line Input is that it simply ignores the null characters and moves to the next character and reads that in. So any data checking I do past this point is pointless because the nulls are no longer in my array.

Thanks for your help!
 
See a couple posts away "Text File Import changes text format", for sample code
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top