Jump to content
Sign in to follow this  
jackrabbit

Does AutoIt has something like #IFDEF in C?

Recommended Posts

jackrabbit

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.

Share this post


Link to post
Share on other sites
PsaltyDS

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

Share this post


Link to post
Share on other sites
Jos

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.

:)


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
jackrabbit

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?

Share this post


Link to post
Share on other sites
Jos

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

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
weaponx

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

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.