|
-
Aug 2nd, 2002, 02:19 AM
#1
Thread Starter
Hyperactive Member
**RESOLVED** Line Input but no carriage returns in the file
I've got a file which I want to read in line by line, and for that I would normally use Line Input. But the file's lines are not separated by CR or CRLF which is what MSDN says Line Input needs. Instead, the first and second lines are separated by only a LF, all subsequent lines are separated by a LFLF pair. (I know this from looking at the data in a hex editor, where I see the x'0A' code which is chr10 or LF. There are no x'0D' chr13 CRs in the file at all)
Indeed when I use Line Edit in a Do..Loop and step thru' the program I can see it only goes thru' the loop once and thus treats the whole file as one line.
I had thought of using a stream edit approach to put the CRs in, but that might be unnecessary if anyone has a better idea?
Thanks...
Last edited by Jim Brown; Aug 2nd, 2002 at 02:59 AM.
.
-
Aug 2nd, 2002, 02:41 AM
#2
Can you use the Split Function at the LF to load an Array.
Like:
VB Code:
lineArray= Split(Input(LOF(1), 1), chr(10))
Or
VB Code:
lineArray= Split(Input(LOF(1), 1), vbLf)
-
Aug 2nd, 2002, 02:58 AM
#3
Thread Starter
Hyperactive Member
That's great Bruce, thanks.
Except I had to make the delimiter vblf & vblf on account of I've got a pair. If I don't then I get a blank line as every second entry in the array.
Now I'll have to work around the fact that line1 & 2 are separated by a single vblf, while the subsequent pairs of lines have two. So at the moment I've still got the first 2 lines joined by their single lf. As it happens the first line's a header and I want to ditch it anyway so I'll figure that out I'm sure.
-
Aug 2nd, 2002, 07:44 AM
#4
Jim,
One soulution Iv'e used in this situation, is to only load my
extraction Variable (or other Array, or whatever) with valid
data. ie Anything other than the LF.
In other words, take the loaded Array (including the double LF's)
and when reading out the lines of data, ignore the LF's.
Like:
VB Code:
Do Until (end of Array)
If lineArray(x) <> "vbLf" Then newArray(z) = lineArray(x)
Bla, Bla
Last edited by Bruce Fox; Aug 2nd, 2002 at 07:48 AM.
-
Aug 2nd, 2002, 07:51 AM
#5
Retired VBF Adm1nistrator
You could always try this
VB Code:
Open "c:\someFile.txt" For Binary As #1
Dim strBuff As String: strBuff = Space(Lof(1))
Get #1, , strBuff
'' strBuff now contains the contents of the file
Close #1
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Aug 2nd, 2002, 08:06 AM
#6
Thread Starter
Hyperactive Member
Bruce's original suggestion of Split, but using 2x LFs worked fine. The first element which then contained the first 2 lines with 1x LF just got Split again looking for only one LF. Then I discarded the resulting first element (the header) and only put the 'right hand part' (the second record, but the first one I actually keep) back into the array.
Then each record gets a Split into the constituent fields.
Then Murphy struck (no offense Jamie!).... when it was finished we found out that not all fields are necessarily present in every record. There are no 'empty' or 'zero' fields for items not required, they're just not there and everything's bumped to the left every time one's missing. So now I'm buggering around to make sure that I'm not misinterpreting fields in the wrong position.
Luckily each field needs an identifier so I can check if the right one's in the right place.
Whoever designed this file was (indeed, probably still is) a ******.
-
Aug 2nd, 2002, 08:11 AM
#7
......when it was finished we found out that not all fields are necessarily present in every record.
Bugger
-
Aug 2nd, 2002, 08:25 AM
#8
Thread Starter
Hyperactive Member
Originally posted by Bruce Fox
Bugger
Not exactly the word I used, but the right sentiment...
-
Aug 2nd, 2002, 08:30 AM
#9
Originally posted by Jim Brown
Not exactly the word I used, but the right sentiment...
LOL. 
Well, good luck Mate.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|