Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

write string to text

Hello everyong,

Please help me .

I need get data from database, format and write to text file.

my code is the following:

intfilehandle = FreeFile
Open test.text For Output As #intfilehandle

' get data and format

strtemp = Join(FArray, "")
Print #intfilehandle, strRetp
rs .MoveNext

it is about 5000 rows in table.
It took more than 1 hour to finish writing .How can I make it faster to write string to text file?

thanks
[553 byte] By [whygh] at [2007-11-11 7:52:59]
# 1 Re: write string to text
three things:
1) 5000 rows is a lot of data, even after optimizing the process will take some time
2) the Join function is extremely slow (and costly)
3) accessing file in text mode is slow

I suggest you to open the file in Binary (that is the fastest way), and to write the data right away instead of joining it together. Or to do one step at the time, and see how it goes

Marco
mstraf at 2007-11-11 17:26:17 >
# 2 Re: write string to text
Also, make sure you use DoEvents if you're looping to ensure the app. doesn't hog all your resources.
RHelliwell at 2007-11-11 17:27:17 >
# 3 Re: write string to text
Also, make sure you use DoEvents if you're looping to ensure the app. doesn't hog all your resources.
careful on that! DoEvents will process also the click on the "X" button, causing the application to exit in the middle of writing the file...
mstraf at 2007-11-11 17:28:17 >
# 4 Re: write string to text
Well yes, there's always that. But you could 'lock' the form when the process begins to ensure it finishes.
RHelliwell at 2007-11-11 17:29:23 >