CyberSlug Posted May 8, 2004 Posted May 8, 2004 Until AutoIt gets full debugging features, the following might help some people: Func Debug($message) If $message = "#ds" Then WinActivate(AutoItWinGetTitle()) ElseIf $message = "#de" Then WinWaitClose(AutoItWinGetTitle()) Else Local $previous = ControlGetText( AutoItWinGetTitle(),"", "Edit1") ControlSetText( AutoItWinGetTitle(),"", "Edit1", $previous & $message & @CRLF) EndIf EndFunc 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!
Developers Jos Posted May 8, 2004 Developers Posted May 8, 2004 (edited) CyberSlug, 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 EndIf Also have a LUA function that will COMMENT or UnComment all "### Debug Window" script lines for ... Edited May 8, 2004 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.
steve8tch Posted May 10, 2004 Posted May 10, 2004 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... ;debug.au3 ; ;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) FileWriteLine($x_debug,$y) If Not StringInStr($yy,"@error") Then FileWriteLine($x_debug,"FileWriteLine($xx," & $line & ")") EndIf ProgressSet(50,"line = " & $line) $line = $line + 1 Wend FileWriteLine($x_debug,"FileClose($xx)") ProgressOff() MsgBox(0,"","done") On a couple of scripts I have tested it on - it seems to work OK. Enjoy
trids Posted May 11, 2004 Posted May 11, 2004 That is just sooooooo cool, Sluggie!Three cheers, that man!
CyberSlug Posted May 23, 2004 Author Posted May 23, 2004 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.expandcollapse popup; 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 sleep(100) hotkeys() 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) EndIf WEnd Exit Func appendText($new) Local $old = ControlGetText(AutoItWinGetTitle(), "", "Edit1") ControlSetText ( AutoItWinGetTitle(), "", "Edit1", $old & @CRLF & $new) WinActivate(AutoItWinGetTitle()) EndFunc Func hotkeys() If WinActive(AutoItWinGetTitle()) Then HotKeySet("{F11}", "clearLog") Else HotKeySet("{F11}") EndIf EndFunc Func clearLog() ControlSetText ( AutoItWinGetTitle(), "", "Edit1", "") Send("{AltDown}{Tab}{AltUp}");active previous window EndFunc Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now