Txt file I/O

  • Thread starter Thread starter pechoi
  • Start date Start date
P

pechoi

Hi,
Is there any way to search then start reading line from search line?
For instance I have input as:
Game#1
Player1 Player2
Game#2
Player2 Player3

Search for Game#2 and start reading file from there.

THank you,
 
You need to normalize your data to look like this --
GAME PLAY1 PLAY2
Game#1 Player1 Player2
Game#2 Player2 Player3

GAME, PLAY1, and PLAY2 are field names in the table.
 
Hi,
Is there any way to search then start reading line from search line?
For instance I have input as:
Game#1
Player1 Player2
Game#2
Player2 Player3

Search for Game#2 and start reading file from there.

Not that I can think of. I believe you'll need to open the file, read
lines in a loop until you come to the one beginning "Game#2", and then
go on from there.
 
Dirk Goldgar said:
Not that I can think of. I believe you'll need to open the file, read
lines in a loop until you come to the one beginning "Game#2", and then
go on from there.

Depending on how big the file is, you could read the entire file into a
variable, and then manipulate the variable.


Dim intFreeFile As Integer
Dim lngFileSize As Long
Dim strBuffer As String
Dim strFileToRead As String

lngFileSize = FileLen(strFileToRead)
strBuffer = Space(lngFileSize)

intFreeFile = FreeFile
Open strFileToRead For Binary As intFreeFile
Get #intFreeFile, , strBuffer
Close intFreeFile


Don't forget that the string will now include all of the carriage
return/line feed characters now: you'll have to handle them yourself.
 
Douglas J. Steele said:
Depending on how big the file is, you could read the entire file into
a variable, and then manipulate the variable.

True, but if subsequent processing is going to be line-oriented, I think
it's easier just to read it line by line.
 
Dirk Goldgar said:
True, but if subsequent processing is going to be line-oriented, I think
it's easier just to read it line by line.

Put it in an array:

Split(strBuffer, vbCrLf)

I think it'll be faster when it's in memory than reading the file line by
line.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top