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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NULL Characters in text file

Status
Not open for further replies.

chimaera

Programmer
Oct 29, 2001
10
US
hi there...
have a problem here and hopefully you guys here can help me with...

i'm reading a text file which is basically a fixed length data file to be put into a database.

the problem i face is that there are some records with NULL characters in it and it seems to dissappear whenever i transfer the whole line into a string...

eg: ABCD1234<NULL>XYZ - text file
what i get when use &quot;Line Input #1, str&quot; is ABCD1234XYZ

is there any way i can recognize the NULL character?
SQL DTS also has the same problem and i cant seem to find a solution for this...

thanx
regards,
Peter
 
Have you tried using InStr and vbNullChar to see if the string contains any null characters? vbNullChar is basically Chr(0), and it may actually be in your line input from the text file. If InStr(str, vbNullChar) returns something other than 0, then you have a null character, and the number you got back tells you where the first one is.

If Line Input is stripping out null characters, not sure what to do...
 
i get a 0 when i use InStr... the NULLs are just stripped out....

if i open the file in binary mode and use Input #1 instead, i only get the part before the NULL...
 

vbnull, vbnullchar, vbnullstring... none gives me the right answer...
but this does..
dont know how practical this could be..

Str1 = &quot;123145&quot;
MsgBox InStr(1, Str1, &quot;&quot;) All the Best
Praveen Menon
pcmin@rediffmail.com
 

Give this a try...
[tt]

Dim S As String, FName As String, FNumb As Integer

FName = &quot;Your Path File Name&quot;
FNumb = FreeFile
Open FName For Binary Access Read As #FNumb

S = Input(Len(FName), #FNumb)

Close #FNumb

S = Replace(S, Chr(0), &quot; &quot;)
[/tt]

BTW, if this solves your problem then you should post that the problem has been solved in all of the threads that you have started.

Good Luck


 
I encountered this in VB3 and it must have persisted through VB6. Chr(0) is dropped by IO routines that read ASCII rather than binary. I had to resort to reading binary, replacing chr(0) with &quot; &quot;, rewriting a new file then reading the new file as ASCII. I can not say what the FileSystenObject does with Chr(0). Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Also, to create a string like this (&quot;123145&quot;), type 123 in Notepad, and then hit three Ctrl+BackSpace... All the Best
Praveen Menon
pcmin@rediffmail.com
 
I don't know whether this will help or not, but I have a VB6 routine that reads a text file with null characters in it and it reads them just fine (without reading binary). The difference may be that I read a specific number of characters rather than an entire line at a time. BlackburnKL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top