Mbee

Any way to easily ignore debug code during compile?

5 posts in this topic

#1 ·  Posted (edited)

I'm an old, long-time programmer and have learned dozens of languages over the years (anyone remember Univac Macro, or MAD?), but I adore AutoIt like crazy!  But although I'm not a noob any more, there's no denying there's a lot left to learn.

In some languages, there's one or more techniques for conditional compilation; for example, if some kind of compiler level variable/value is set to True or False (for example), the compiler can exclude some debug-only code, instead of forcing the programmer to simply comment out all the debug code (which is a real pain!)

Now, I found a request to add a new capability for something the author referred to as "conditional compliation" (see: Conditional Compilation (#if, #ifdef, #ifndef, #else, #elif, #endif, and defined) - REJECTED). But what that poster was asking for is vastly more difficult and extensive than what I'm thinking of, that's for sure!  All I want is something like this:

If %Debug ON
    Here's some special debugging code that I want to exclude from compilation...
EndIf

One of the main reasons I'd like something like this simple feature is for using the graphical debugger. It's very annoying to have to step or run though all the sub-sections of my code that are only useful before the code is already working reasonably well. In my case, I'm using a UDF written by Kobashi called "StatusMsgs" to display status messages very, very frequently during the earllier stages of debugging a GUI. I spent a lot of time adding all those status messages, and if I run across a problem in the future (say if a third-party user runs across some strange behavior or a bug), and I need additional info in order to debug the problem, it would be great to be able to enable compiling the debug code again.

Is there any relatively easy way to do that with AutoIt as it exists now, or do I have no choice but to comment/de-comment the debug code?

Thanks!

Edited by Mbee

Share this post


Link to post
Share on other sites

Let's assume you call the status message with this line

StatusMsg(...)

you could simply use the SciTE editor (Ctrl+h) to change all those lines to comments:

; StatusMsg(...)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

@Mbee,

make a smart use of the @Compiled built-in macro.

for example, in the UDF, go inside the assumed function StatusMsg(), that @water mentioned above. add a line just at the beginning of the function, such as:

If @Compiled Then Return

so if the code is compiled, the function returns without doing anything.

note that you need to see what return values are expected under normal operation, and mimic them.

Share this post


Link to post
Share on other sites

My thanks to both Water and orbs. I am grateful for your replies.

 

Share this post


Link to post
Share on other sites

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now