
Write to a log file using a new thread
Hi Michael,
this is the structure i could use to solve your problem:
1. program starts from <sub Main>
2. the user form object is <UserForm>
3. <LogCommandID> is the integer variable we are using to pass log commands.
You set this variable to a non-zero value when user interacts with UserForm
(through command buttons or something)
4. <AppendToLog(LogCommandID%)> is the procedure to printout your log data
Public LogCommandID%
Sub Main
LogCommandID = 0
UserForm.Show (=NOT modal, execution continues)
Do
If (LogCommandID=0) Then
DoEvents
Else
AppendToLog(LogCommandID)
LogCommandID = 0
End If
Loop
End Sub
Dont forget to end the program through the Unload event of UserForm (or put
a control variable to the Do..Loop)
Quote:
> I would like to write to a log file everytime a user performs a function
in
> my app. This will only be used for debugging purposes, and the amount of
> information being written would be very high.
> Therefore it needs to be in a new thread. How can I send information from
> the main apps functions to the thread so it can write to the log file. I
do
> not want to create a thread everytime the user performs a function I would
> like to create 1 thread when the app starts and just pass information to
it.
> EG..
> User starts application, the logging thread is created, from here on out
> everything done in the main application is sent to the logging thread.
When
> the user click a command button it would pass "frmMain, function
> 'OpenStaff', cmdOpen CLICKED" and the logging thread would recieve this
text
> and write to the log file.