473,405 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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
Nov 13 '05 #1
2 3792
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: byrocat | last post by:
Sybase and DB2 both have the capability of tracking user activities at a number of levels: invalid access attempts to databases, table, etc.; creation/deletion/modification of database...
2
by: Marc | last post by:
I'm back in the Access development mode and seem to have forgotten how to do 2 things that should be simple. I have a database with a table of contacts, companies and activities. The idea is that...
2
by: Tim Cowan | last post by:
Hi, Does anyone have any examples/tutorials of FTP functionality using .NET 2.0? I want to connect to the server, get a list of files and download/upload all in C#. Can someone help? ...
4
by: diego | last post by:
Hi everyone, What is an effective way of storing user activites while using my program? Like when a user clicks on a button, i would like ro save the following in a log file, "Clicked Edit...
1
by: Subrato | last post by:
Hi, I am very new to xml and I have this piece of code which I took off a website. The situation is that on of the website, user files up a form and it is submitted. On submission, the page should...
11
by: Don Barton | last post by:
I am trying to update a table using VBA and SQL. A form is filled out with user ID and PW, then these data are sent to global variables. The global variables are used to create a record in...
2
by: David Haskins | last post by:
I have a fairly complex interface screen (form) that is comprised of several subforms that perform different, but related activities. I am designing a search/filter form that should be able to...
1
by: Mientje | last post by:
I've made an Access 2007 database to store information about the lessonplans I have to make every schoolyear. I want to export the data form the table "Lesvoorbereiding" (Lessonplans in English) to...
2
by: lhsiber | last post by:
I am new to access and am having a problem with filtering. Here is a little bit of my setup: I have a main form that has a listbox so that users can choose one or many groups in which to display...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.