Jump to content

Does AutoIt has something like #IFDEF in C?


Recommended Posts

Dear all,

In C, we can use #IFDEF to control which portion of the code to run. It is very handy for debug the code. I am wondering if AutoIt has similar feature? I could not find it in the document.

Thanks.

If you mean to prevent multiple inclusion by #include, then the include file should have #include-once at the top. This is good general practice for all include files.

I don't think there are any conditional compiler directives in the AutoIt3Wrapper, but that would be a Jos question...

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Developers

If you mean to prevent multiple inclusion by #include, then the include file should have #include-once at the top. This is good general practice for all include files.

I don't think there are any conditional compiler directives in the AutoIt3Wrapper, but that would be a Jos question...

:)

Nope, No conditional compiler directives available.

... but there are many other options to do optional debugging.

:)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Nope, No conditional compiler directives available.

... but there are many other options to do optional debugging.

:)

Thank you guys. I want to use that feature for debugging.

For example, when I debug, I want to print out some messages with MsgBox. When I run the code regularly, I want to turn off those MsgBox. Now I have to manually turn them on and off. It is really painful since these msgbox are at different locations in the code. I am wondering how can I turn them on and off in one shot in AU3?

Link to comment
Share on other sites

  • Developers

Something like this could work too:

$debug = Number(IniRead("pgm.ini", "main", "debug", "0"))
$a = 1
$b = 1
; some code
Debug($a)
; some code
Debug($b & " test2")
; Some code

Func Debug($var)
    If not $debug Then Return
    MsgBox(0, "debug", $var)
EndFunc  ;==>Debug
Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

You could be creative...

Global Const $Debug = True

_Debug("Title", "Message", 0)

Func _Debug($sTitle,$vVar,$iMode=0)
    If $Debug Then
        $sOutput = ""
        
        ;If array is passed, flatten to string
        If IsArray($vVar) Then
            For $X = 0 to Ubound($vVar)-1
                $sOutput &= "["&$X&"]: " & $vVar[$X] & @CRLF
            Next
        EndIf
        
        ;Debug to console or message box
        If $iMode = 0 Then
            MsgBox(48,$sTitle,$vVar)
        Else
            ConsoleWrite($sOutput)
        EndIf
    EndIf
EndFunc
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...