devxlogo

Debug Print in an EXE

Debug Print in an EXE

Contrary to common belief, Debug.Print statements are not always removed from an executable. This behavior can be demonstrated easily. Open a new project, place a single CommandButton on the default form, and add this code:

 Public Function DebugTime()	MsgBox "Caught!"End FunctionPrivate Sub Command1_Click()	Debug.Print DebugTimeEnd Sub

Compile the program to an EXE, run, and click on the button. Unexpectedly, the message box appears. This is obviously a contrived example, but it’s easy to imagine cases where Debug.Print is used to print the return value of a function, for example. If variables are passed as ByRef parameters, and if the function alters the value of those variables, this error is propagated through to the executable, and might be extremely difficult to find. The morals of this tip are:
1. Pass parameters ByVal unless you’re certain you’re not going to change them, or you’re using them as “output” parameters.
2. Be careful when using Debug.Print. It might be doing more than you think.

See also  5 Tips for Choosing the Right Medical Software for Your Practice
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist