Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2006

Tip: Looking for answers? Try searching our database.

How can I create a large text file is an efficient way?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Oscar - 14 Mar 2006 09:50 GMT
I 've coded a subroutine to create a text file (in this case a xml file)
which sometimes holds a size of  500 - 900 KB. While the subroutine works
efficiently for small file size (up to 50 KB) I noted a worse efficiency in
case of large file size (up to 10 minutes of calculation time).

This is the routine :

Set fso = CreateObject("Scripting.FileSystemObject")
Set xmlFile = fso.CreateTextFile(FilePath, True)

DO
   xmlFile.Write "some text" & vbCrLf

LOOP UNTIL ..

xmlFile.Close

While debugging I've noted that the execution of  line : xmlFile.Write ...
takes more and more time as the text file has grown lager.

Is there a more efficient way to create the text file ?

Regards,
Oscar
Jezebel - 14 Mar 2006 10:13 GMT
1. Don't use the Scripting object. The native file commands are simpler,
quicker, and more reliable.
2. Construct the file in memory then write it in one operation:

Dim pFileNum as long
Dim pFileText as string

Do
   pFileText = pFileText & "sometext" & vbCr
Loop until ...

pFileNum = freefile
open FilePath for output as pFileNum
Print #pFileNum, pFileText
Close #pFileNum

>I 've coded a subroutine to create a text file (in this case a xml file)
>which sometimes holds a size of  500 - 900 KB. While the subroutine works
[quoted text clipped - 20 lines]
> Regards,
> Oscar
Oscar - 14 Mar 2006 14:44 GMT
Hi Jezebel,

I've done that but the performance didn't improve at all.

Oscar

> 1. Don't use the Scripting object. The native file commands are simpler,
> quicker, and more reliable.
[quoted text clipped - 36 lines]
>> Regards,
>> Oscar
Karl E. Peterson - 14 Mar 2006 18:58 GMT
> I 've coded a subroutine to create a text file (in this case a xml
> file) which sometimes holds a size of  500 - 900 KB. While the
> subroutine works efficiently for small file size (up to 50 KB) I
> noted a worse efficiency in case of large file size (up to 10 minutes
> of calculation time).

This multipost was answered, very well, elsewhere...  <sigh>
Signature

Working without a .NET?
http://classicvb.org/

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.