Jump to content

Any way to easily ignore debug code during compile?


Recommended Posts

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
Link to comment
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

:)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...