Guus2005
AWF VIP
- Local time
- Today, 14:53
- Joined
- Jun 26, 2007
- Messages
- 2,642
I need to write about a million records to a text file.
There are several ways to accomplish this. I need the fastest ofcourse.
Method #1
Method #2
Method #3
The string which needs to be written is concatenated using FastCat.
I expect writing a single line takes more time than writing n lines at once. So i am writing n lines at once.
But i need advice on the fastest method. Is there a fourth method even quicker?
Thanks!
There are several ways to accomplish this. I need the fastest ofcourse.
Method #1
Code:
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("c:\testfile.txt", True)
a.WriteLine("This is a test.")
a.Close
Method #2
Code:
Open "c:\testfile.txt" For Output As #1
Print #1, "This is a test"
Close #1
Method #3
Code:
Set objStream = CreateObject("ADODB.Stream")
With objStream
.Open ' Open new stream
.Type = 2 ' type 'Text' (adTypeText)
.Charset = "utf-8" ' charset UTF-8
.Position = 0 ' from the start
.LineSeparator = -1 ' close every record with CRLF
.WriteText "This is a test", 1 ' (adWriteLine)
.SaveToFile "c:\testfile.txt", 2
.Close
End With
The string which needs to be written is concatenated using FastCat.
I expect writing a single line takes more time than writing n lines at once. So i am writing n lines at once.
But i need advice on the fastest method. Is there a fourth method even quicker?
Thanks!