Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old November 13th, 2005, 12:13 PM
Mark
Guest
 
Posts: n/a
Default Using Code to log activities in a text file

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
Default 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
Default 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


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles