The debug function is very helpful while tracing program execution but it does not work from a compiled application. From time to time I have encountered bugs that only surface in the compiled version. So I wrote a routine I call 'TraceWrite' to create a log of application execution points. Tracing the execution may help determine where the program is failing. I recently needed 'TraceWrite' to help debug a rather nasty error. I made a few improvements and decided to make this the May 2002 tip-of-the-month.
I created a VB 6 demo program to show how to use 'TraceWrite''. Demo program screens:
Trace Log Demo
The Trace Log
Function, Arguments Description TraceOpen sFileName, [bClear] Open the log file and optionally clear it. sFileName A fully qualified file name. bClear If True the log file is opened as a new file. Optional. Default is 'True'. TraceWrite sText Write, by appending, to the log file. sText Any string.
Sample call to TraceOpen and TraceWrite '--------open trace log ----------------
TraceOpen AddBackslash(App.Path) & mcsTraceLog, True
'--------write to the trace log --------
TraceWrite Now & " In DoTraceWrite, Count " & iCounter
Conditional Compilation Argument 'TraceWrite'
Trace routines are operative only if conditional compilation argument 'TraceWrite' is on. To control this setting us the Project Properties, Make tab, for example:
TraceWrite set 'on'.
This VB 6 dialog box has been enlarged.
See tip: "Make VB's Dialog Boxes Larger" for details.
You will probably want to turn off the Trace feature when you distribute the application. Otherwise a trace log will be created every time the application is executed.
The Demo Program Uses These Modules
Module - Click for More Info Description Used in the Demo To modTraceWrite.bas Contains functions TraceOpen and TraceWrite The subject of this tip. Add it to your application to use the functions. modConnectToWebSite.bas Connect to a web site Show this info when Help/Info is selected from the demo. modAddBackSlash.bas Add a backslash if needed. Add a backslash to App.Path
Download VB 6 Source Code
Click here to download the VB 6 source code [9k]
Previous Tip Tip Index Next Tip