Jump to content

Recommended Posts

Until AutoIt gets full debugging features, the following might help some people:

Func Debug($message)
    If $message = "#ds" Then
    ElseIf $message = "#de" Then
        Local $previous = ControlGetText( AutoItWinGetTitle(),"", "Edit1")
        ControlSetText( AutoItWinGetTitle(),"", "Edit1", $previous & $message & @CRLF)

Example usage:

Debug('#ds') ;open log window

; start of script goes here...

Debug("The value of some variable foo is:" & $foo)

Debug("Another debug message")

; end of script...

Debug('#de') ;keep log window open until you close it

P.S. If anything similar (most likely better) has been posted before, let me know. I didn't find anything with a quick forum search.

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to post
Share on other sites
  • Developers


This is a simple but very effective debugging idea for scripts!

Just took your idea and made a LUA function in Scite that add a debug statement in the code by just pressing a Ctrl+SHift+D :

Example: I put my cursor on $test and hit Ctrl+Shift+D and it created the frst line:

Debug("variable $Test:" & $Test);### Debug Window
If $Test = '/test' Then
   ' do something

Also have a LUA function that will COMMENT or UnComment all "### Debug Window" script lines for ...

Edited by JdeB

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 post
Share on other sites

I am having problem with a script - see 'bugs' section - so I have writen a few lines that will add a filewriteline statement after every line in a script - the idea is that if the script stops somewhere or just bombs out - you can then trace the exact line that it happened on.

I have chosen just to write out the original script line number- nothing stops anybody changing what is written out - eg tracing some variables etc.

Here goes...

;Just a quick bit of code to write out a debug script
;Run debug - choose a file - the script will then write out file
;called filename_debug.au3  This file should be identical to your 
;script except that afer every line of code there is an 
;instruction to write out the original script line number to a text file.
;If the script crashes out - you just look at the the last line written out 
;to indicate where the script crashed.

$file = FileOpenDialog("choose file to add debug info to",@ScriptDir,"(*.au3)",1)
$file_debug = StringTrimRight($file,4)
$x = FileOpen($file,0)
$x_debug = FileOpen($file_debug & "_debug.au3",2)
FileWriteLine($x_debug,"$xx = FileOpen(""" & $file_debug & "_debug_log.txt"",2)")
$line = 1
ProgressOn($file,"Adding debug info..","",-1,-1,16)
While 1
   $y = FileReadLine($x,$line)
   If @error = -1 Then ExitLoop
   $yy = FileReadLine($x,$line + 1)
   If Not StringInStr($yy,"@error") Then
      FileWriteLine($x_debug,"FileWriteLine($xx," & $line & ")")
   ProgressSet(50,"line = " & $line)
   $line = $line + 1

On a couple of scripts I have tested it on - it seems to work OK.

Enjoy :D

Link to post
Share on other sites
  • 2 weeks later...

Here's something inspired by this thread.

Run this program in the background. Then run other scripts. If you run a script containing a syntax error (or other error that causes an AutoIt Error dialog to appear), the message is logged to "Error Messages" window. Press F11 to clear the output and return focus to the previous window.

Hope that makes sense.

; Run this before you run other AutoIt scripts
Opt("WinTitleMatchMode", 1)    ;1=start, 2=subStr, 3=exact, 4=...
$title = "AutoIt Error"

AutoItWinSetTitle("Error Messages")
WinActivate(AutoItWinGetTitle ())

While 1
    If WinActive($title) Then
        $text = ControlGetText ( $title, "", "Static2" )
        ControlClick ( $title, "", "Button1")
        $text = StringReplace($text, @LF & @LF, @LF);remove double spacing
        $text = StringReplace($text, @LF, @CRLF)
        appendText($text & @CRLF)

Func appendText($new)
    Local $old = ControlGetText(AutoItWinGetTitle(), "", "Edit1")
    ControlSetText ( AutoItWinGetTitle(), "", "Edit1", $old & @CRLF & $new)

Func hotkeys()
    If WinActive(AutoItWinGetTitle()) Then
        HotKeySet("{F11}", "clearLog")

Func clearLog()
    ControlSetText ( AutoItWinGetTitle(), "", "Edit1", "")
    Send("{AltDown}{Tab}{AltUp}");active previous window
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...