Connecting Tech Pros Worldwide Help | Site Map

Using Code to log activities in a text file

  #1  
Old November 13th, 2005, 12:13 PM
Mark
Guest
 
Posts: 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


  #2  
Old November 13th, 2005, 12:14 PM
Bas Cost Budde
Guest
 
Posts: n/a

re: Using Code to log activities in a text file


Mark wrote:
[color=blue]
> 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.[/color]

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

  #3  
Old November 13th, 2005, 12:15 PM
Mark
Guest
 
Posts: n/a

re: Using Code to log activities in a text file


No that was fine. Worked exactly as needed thank you very much

Mark

"Bas Cost Budde" <b.costbudde@heuvelqop.nl> wrote in message
news:d99vj4$pld$1@localhost.localdomain...
Mark wrote:
[color=blue]
> 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.[/color]

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


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
.Net frameword Resources ( vb.net , asp.net etc...) shamirza answers 0 January 17th, 2007 08:05 AM
Py2exe and logging module sfbell09 answers 1 July 18th, 2005 05:41 AM