find last line quick

A

arno

Hi,

I have been asked to do some work on a elaborate vba system. One of its
features is reading the last line of a textfile, updating a counter, and
adding a new line. In the current implementation, this text-file is read
into Word, and using some nifty command, Word is told to jump to the end
of the text/paragraph (?).

My question is, if there is a penalty performance-wise when opening a
text-file in Word, and whether it might be faster to just use a
TextStream.

If the latter, my next question is how to best deal with a situation in
which some user has added empty lines to the end of it containing just
line-breaks (enter-enter-etc.). They shouldn't, buy hey, end-users ;-).
EOF would be 'too far', and checking every line might be slower than the
current method.

My gut-feeling tells me it is better to use a database system for this,
but I am not at liberty to change too much, and I might even be wrong.

I suppose I am not so much looking for answers, but rather for
guidelines/suggestions/best practices.

tia
arno
 
S

Steve Rindsberg

Hi,

I have been asked to do some work on a elaborate vba system. One of its
features is reading the last line of a textfile, updating a counter, and
adding a new line. In the current implementation, this text-file is read
into Word, and using some nifty command, Word is told to jump to the end
of the text/paragraph (?).

My question is, if there is a penalty performance-wise when opening a
text-file in Word, and whether it might be faster to just use a
TextStream.

If the latter, my next question is how to best deal with a situation in
which some user has added empty lines to the end of it containing just
line-breaks (enter-enter-etc.). They shouldn't, buy hey, end-users ;-).
EOF would be 'too far', and checking every line might be slower than the
current method.

My gut-feeling tells me it is better to use a database system for this,
but I am not at liberty to change too much, and I might even be wrong.

I suppose I am not so much looking for answers, but rather for
guidelines/suggestions/best practices.

Reading/Writing text files directly from VB/VBA is quite fast. Lightning
compared to waking up Word to do the job, and more reliable as well.

If you search at http://www.pptfaq.com for "text file" you'll find several
examples of reading/writing text directly.

Most read a line at a time into a buffer variable, then do something with
it. It'd be simple enough to do something like this to ignore blank lines:

' Read a line into sBuf
If Len(trim(sBuf)) > 0 Then
' Do whatever
End If
 

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

Top