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 / February 2006

Tip: Looking for answers? Try searching our database.

Which is better: files or textStreams?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rhino - 02 Feb 2006 14:14 GMT
I have a macro that reads one external file and that writes entries to a log
file, if and when it encounters errors. Both the external file and the log
file are simple text files.

I know from the VBA help that I can work with either files or textStreams
but I don't see anything in the help that says why one would be better than
the other. Can anyone enlighten me on this subject?

What are the pros and cons of files vs. textStreams?

At the moment, I have my options open, but I'd like to make a decision about
which to use. For instance, my macro currently does the following:

   Private Const WRITEONLY As Integer = 2
   Private Const LOG_IS_TEXTFILE = True
   Private Const LOG_FILE_NAME As String = "c:\word_log.txt"

   If (LOG_IS_TEXTFILE) Then
       Set logFileObject = CreateObject("Scripting.FileSystemObject")
       logFileObject.CreateTextFile (LOG_FILE_NAME)
       Set logFile = logFileObject.GetFile(LOG_FILE_NAME)
       Set logTextStream = logFile.OpenAsTextStream(WRITEONLY,
TRISTATE_USE_DEFAULT)
   Else
       logFileNumber = FreeFile
       Open LOG_FILE_NAME For Output As logFileNumber
   End If

   If (LOG_IS_TEXTFILE) Then
       logTextStream.write "Unexpected key, " & resumeFileKey & ", found in
file."  & vbCrLf
   Else
       Write #logFileNumber, "Unexpected key, " & resumeFileKey & ", found
in file."
   End If

   If (LOG_IS_TEXTFILE) Then
       logTextStream.Close
   Else
       Close logFileNumber
   End If

But this is silly: surely one or the other is the better choice so I'd like
some advice on which to use so that I can remove the code that writes the
other format.

By the way, one related question. When I have LOG_IS_TEXTFILE set to False,
every line written into the log file has a pair of quotes around it but this
doesn't happen when the boolean is set to True. Why is that?

Signature

Rhino

Jezebel - 02 Feb 2006 14:41 GMT
If you trawl the VB forum, you'll see that the consensus is that the
FileSystemObject is something that you wish hadn't stood in. There is really
nothing it does that you can't do just as easily using native commands -- so
why add the complexity of another library?

>I have a macro that reads one external file and that writes entries to a
>log file, if and when it encounters errors. Both the external file and the
[quoted text clipped - 45 lines]
> False, every line written into the log file has a pair of quotes around it
> but this doesn't happen when the boolean is set to True. Why is that?
Rhino - 02 Feb 2006 14:55 GMT
Thanks for settling that!

I was leaning towards files anyway - fewer lines of code to do the same
thing, particularly on the open - but I thought there might be some big
benefit to textStreams that I didn't know about, like performance or
security. Since there apparently isn't any such benefit, I'll stick to good
old files then.

--
Rhino

> If you trawl the VB forum, you'll see that the consensus is that the
> FileSystemObject is something that you wish hadn't stood in. There is
[quoted text clipped - 50 lines]
>> False, every line written into the log file has a pair of quotes around
>> it but this doesn't happen when the boolean is set to True. Why is that?
 
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.