R
Rhino
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?
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?