Re: Reading a text file
From: Björn Holmgren (bjohol_at_hotmail.com)
Date: 06/14/04
- Next message: Bob Butler: "Re: Reading a text file"
- Previous message: Mr. Lee: "Make vbScript An Exe"
- In reply to: Brian: "Reading a text file"
- Next in thread: Brian: "Re: Reading a text file"
- Reply: Brian: "Re: Reading a text file"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 14 Jun 2004 16:37:47 +0200
"Brian" <bfordSPAMOFF@markem.com> wrote in message
news:#jVl8vhUEHA.3780@TK2MSFTNGP10.phx.gbl...
> I need to use VB6 to read in and parse through a text file one line at a
> time, I was hoping to use Line Input but that doesn't work becaue the text
> file only contains a line feed and no carriage returns.
>
> How can I read in 1 line at time with only the line feed to work with? do
I
> have to do this one char at a time, I hope not :(
You can't read it line by line if VB doesn't recognize the linefeed.
Try reading it all at once into a string variable and then splitting it into
individual elements based on the linefeed character.
Example (air code):
Const TEXT_FILE = "C:\Temp\MyFile.TXT"
Dim F As Long
Dim sBuffer As String
Dim sLines() As String
Dim Index As Long
F = FreeFile
Open TEXT_FILE For Binary Access Read As #F
sBuffer = String(FileLen(TEXT_FILE), " ")
Get #F,,sBuffer
Close #F
sLines = Split(sBuffer, vbLF)
For Index = LBound(sLines)
' Process each line here
Debug.Print sLines(Index)
Next
-- Björn Holmgren Guide Konsult AB
- Next message: Bob Butler: "Re: Reading a text file"
- Previous message: Mr. Lee: "Make vbScript An Exe"
- In reply to: Brian: "Reading a text file"
- Next in thread: Brian: "Re: Reading a text file"
- Reply: Brian: "Re: Reading a text file"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|