By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,652 Members | 1,995 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,652 IT Pros & Developers. It's quick & easy.

Using Code to log activities in a text file

P: n/a
Hi All,
I am trying to keep a log file of what is going on with my frontend. I
have achieved this with the following code:

Dim fs, f

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("K:\Systems\Backup\Error log\housekeeping.txt",
8, TristateFalse)
f.Write Now() & " " & fOSUserName() & "some other meaningful text here"
vbCrLf & _
""
f.Close

Rather than have this code repeated several times in each procedure where I
want to log something, I would rather have this code stored as a module and
then call it whenever needed. I would also need to add some text to it which
will vary depending on where in the code I call it.

Could anyone offer advice on how to achieve this?

TIA,

Mark
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Mark wrote:
Hi All,
I am trying to keep a log file of what is going on with my frontend. I
have achieved this with the following code:

Dim fs, f

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("K:\Systems\Backup\Error log\housekeeping.txt",
8, TristateFalse)
f.Write Now() & " " & fOSUserName() & "some other meaningful text here"
vbCrLf & _
""
f.Close

Rather than have this code repeated several times in each procedure where I
want to log something, I would rather have this code stored as a module and
then call it whenever needed. I would also need to add some text to it which
will vary depending on where in the code I call it.


So:
You create a new code module (or use an existing one), just a standard
module.
You create a procedure in this module, where you put your code.
Instead of using literal "meaningful text", you apply a variable (call
it maybe cLine). This variable needs to be passed to the procedure: put
the name of the variable inside the brackets that come with the
procedure header, like this:

Sub LogLine(cLine as string)

Now, when you need your code to run, call it by name, like this:

LogLine "some meaningful text"

this executes all code between Sub LogLine() and End Sub, substituting
the actual text for the variable name.

I hope this answer is not too wordy!
--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html

Nov 13 '05 #2

P: n/a
No that was fine. Worked exactly as needed thank you very much

Mark

"Bas Cost Budde" <b.*********@heuvelqop.nl> wrote in message
news:d9**********@localhost.localdomain...
Mark wrote:
Hi All,
I am trying to keep a log file of what is going on with my frontend. I
have achieved this with the following code:

Dim fs, f

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("K:\Systems\Backup\Error
log\housekeeping.txt",
8, TristateFalse)
f.Write Now() & " " & fOSUserName() & "some other meaningful text
here"
vbCrLf & _
""
f.Close

Rather than have this code repeated several times in each procedure where
I
want to log something, I would rather have this code stored as a module
and
then call it whenever needed. I would also need to add some text to it
which
will vary depending on where in the code I call it.


So:
You create a new code module (or use an existing one), just a standard
module.
You create a procedure in this module, where you put your code.
Instead of using literal "meaningful text", you apply a variable (call
it maybe cLine). This variable needs to be passed to the procedure: put
the name of the variable inside the brackets that come with the
procedure header, like this:

Sub LogLine(cLine as string)

Now, when you need your code to run, call it by name, like this:

LogLine "some meaningful text"

this executes all code between Sub LogLine() and End Sub, substituting
the actual text for the variable name.

I hope this answer is not too wordy!
--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.