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!

Reading a large block of text data from a file?

Status
Not open for further replies.

tedsmith

Programmer
Nov 23, 2000
1,762
AU
I seem to remember with DOS basic that you could read a large block of text into a variable in one go without reading each line in turn with a Line Input # loop and a Stream.
(not binary)
Can't seem to find how to do this in VB6.
Any suggestions?
 
Code:
      Open myFile For Input As filenum
      myVar = Input(LOF(filenum), filenum)
 
Or the FileSystemObject's TextStream's ReadAll method.

Mind you, given the continued lack of feedback in your other threads I'm assuming that you must still be away from your VB computer, however , and therefore that neither of these answers will be of any use for several weeks.
 
Thanks, that's what I was looking for.

strongm is correct - in fact it will be some time before I get back but that doesn't stop me thinking!
I even designed a smell app in my head the other day.

Actually I am on my way to Canada and the USA and won't get back to the land of the really free until mid October.

But don't worry, my neighbor is feeding my kangaroo.
 
Just to mention an alternative, you can read the file for binary input as well.
___
[tt]
Dim Contents As String, FileNum As String
FileNum = FreeFile
Open "C:\test.xml" For Binary Access Read As FileNum
Contents = Space$(LOF(FileNum))
Get #FileNum, , Contents
Close #FileNum[/tt]
___

The important thing is, it is much better and efficient to read the file this way (unless the text file is extremely large), because in this way, the read operation is performed only once.

On the other hand, with Line Input statement, the hard disk is scratched every time a read operation is requested and overall time is also increased.

The time required to read 1 KB of data, 1000 times is much larger than the time required to read 1 MB of data in a single chunk.

After reading the contents, you can also parse the contents line-by-line by performing [tt]Split[/tt] on the received text.
 
Thanks.
In would have originally used myVar = Input(number, filenum) but I didn't think of using LOF(filenum) for number

Is using binary any faster than the above considering you would have to parse the output to turn it back to text?

For smell apps I use sauce code.
 
>considering you would have to parse the output to turn it back to text?

Not necessarily. Depends on whether the source file is ANSI or UTF. If it is a text file you've created yourself from another VB program, then it'll (almost certainly) not need parsing at all. If it is created by Notepad, then it won't need parsing. If it is a typical application log file, then it won't need parsing.

 
I'm currently enjoying the beautiful scenery in Jasper Canada.
Nothing like it in Aussieland!
 
Good luck with the smell app Ted. If you do get it working you may have to change your name to something more appropriate.
How about 'Ted Sniff' [smile2]

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top