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

ReadLine with TextSteam Obj

Status
Not open for further replies.

mikecon

IS-IT--Management
Jun 14, 2001
8
US
I'm seeing what appears to be a weird behavior using the ReadLine method of a TextStream object. The data file is a little funky in that it's UNIX format and, evidently, the COBOL guys who must have made it use hex 00 (null) as their filler character for unused 'fields'. I have to do a bunch of reformatting -- e.g. replace lf with cr+lf and the hex 00s with spaces -- which is pretty straightforward but I noticed records were getting trashed (i.e. swaths of needed text were getting replaced with spaces). I figured my RegExp.Replace had run amuck. But, when I broke it down, it appears to be ReadLine that's misbehaving because when I simply ReadLine my input stream, then WriteLine my output stream -- doing nothing in between -- a bunch of new hex 00 appear where text was before! And it all starts where it encounters the 1st hex 00. The funny thing is, the latter portion of the 'record' is fine! Anybody gotten grief from these hex 00s and ReadLine/WriteLine??? Any ideas how to overcome? Thanx in advance!

mc
 
Feng,

Pretty vanilla...

...

'Input stream
Set oTextIn = oFSO.OpenTextFile(strSubFolder & "\" & strFile, ForReading)
' Reformatted output stream
Set oTextOut = oFSO.CreateTextFile(strSubFolder & "\" & strNewFile)
' Read lines
Do While Not oTextIn.AtEndOfStream
strFileRec = oTextIn.ReadLine
' Here's where reformatting the string might
' happen, but I removed all of that
oTextOut.WriteLine strFileRec
Loop
oTextIn.Close
oTextOut.Close
Set oTextIn = Nothing
Set oTextOut = Nothing

...

---

After breaking it down, that's all I had -- read a line, write a line. I know it was the read that was fouling up, though, because if you stuck a msgbox or inputbox in between it would chop the string at the 350th position -- the first hex 00 it encountered. Funny thing though, if you followed that with a msgbox len(strFileRec), it reported '700' which is, in fact, the full length of each record.

Unfortunately, I can't even copy/paste a sample of the file because none of my editors will let copy the nulls (i.e. the hex 00, i.e. the chr(0)). Something like Notepad appears to but that's only because it converts the nulls to some meaningless 'box' character

I worked around it using 2 loops with Read(1) -- a character at a time -- (instead of ReadLine) inside. This way I can check each newly read character for char(0) before concatenating it to the building string (if I read a chr(0), I'd set the character var to " " and concatenate that to the building string instead. When I read a chr(10) I leave the Read(1) loop and issue WriteLine of the built-up string, then on to the next line. I hope performance doesn't totally suck on a big file and I'm sure I'll peg my CPU.

Sure seems unnecessarily 'loopy' but I had to move on to something else.

Thanx for your interest.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top