AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

sweet&simple debugging message templates

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Stanley Krute



Joined: 30 Jul 2005
Posts: 38

PostPosted: Sat Nov 21, 2009 6:10 pm    Post subject: sweet&simple debugging message templates Reply with quote

Here's one of my favorite sweet&simple debugging message templates:

Code:
; MsgBox % "[debugging]  [line " . A_LineNumber . "]`n`n" . "Put_Some_Var_Name_Here: " . Put_Some_Var_Name_Here


I sprinkle it around my code when debugging some doh!-ness. Paste in a var name and remove the ; when I want to look at a var value. Produces stuff like this:



I imagine other folks may have similar tekn3x. Share away.

-- ahknoob stan
Back to top
View user's profile Send private message Visit poster's website
Stanley Krute



Joined: 30 Jul 2005
Posts: 38

PostPosted: Sat Nov 21, 2009 8:02 pm    Post subject: Reply with quote

Here's a variant of the above, but this template's for multiple vars:

Code:
if 0       ; set to 1 to debug
   {
   scratch := ""
   scratch :=  scratch . "Put_Some_Var_Name_Here: " . Put_Some_Var_Name_Here . "`n"
   scratch :=  scratch . "Put_Some_Var_Name_Here: " . Put_Some_Var_Name_Here . "`n"
   scratch :=  scratch . "Put_Some_Var_Name_Here: " . Put_Some_Var_Name_Here . "`n"
   
   MsgBox % "[debugging]  [line " . A_LineNumber . "]`n`n" . scratch
   }


Replace the var name placeholders, then replace the 0 with a 1 in the if test at the top when you want to see those var values.
Back to top
View user's profile Send private message Visit poster's website
sinkfaze



Joined: 18 Mar 2008
Posts: 2427

PostPosted: Sun Nov 22, 2009 12:24 am    Post subject: Reply with quote

Nice concept, most users come here not knowing how to set their code up for debugging and this is a nice template.

Since you're well familiar with the concatenation operator you could use the continuation section style to concatenate multiple results rather than assigning the variable to itself plus concatenation each time:

Code:
if 0       ; set to 1 to debug
   {
   scratch := ""
   scratch :=  scratch . "Put_Some_Var_Name_Here: " . Put_Some_Var_Name_Here . "`n"
   . "Put_Some_Var_Name_Here: " . Put_Some_Var_Name_Here . "`n"
   . "Put_Some_Var_Name_Here: " . Put_Some_Var_Name_Here . "`n"
   
   MsgBox % "[debugging]  [line " . A_LineNumber . "]`n`n" . scratch
   }

_________________
Try Quick Search for Autohotkey or see the tutorial for newbies.
Back to top
View user's profile Send private message
entropic



Joined: 21 Dec 2008
Posts: 161

PostPosted: Sun Nov 22, 2009 3:25 am    Post subject: Reply with quote

On a side-note I've always thought it would be nice if you could do this:
Code:

    Lines := ListLines()
    Vars  := ListVars()

    FileAppend, %Lines% `n`n %Vars%, DebugLog.txt

Back to top
View user's profile Send private message
gwarble



Joined: 23 May 2009
Posts: 125
Location: north bay, california

PostPosted: Sun Nov 22, 2009 6:04 am    Post subject: Reply with quote

i made Notify() for this purpose without pausing the script... good for variables or labels/timers when a msgbox doesn't cut it, and multiple can be shown... although its evolved into more, i still use it a lot for this:

Code:
Notify("Variable at line " A_LineNumber, Variable)
Notify(A_ThisLabel)

Notify("Var1 = " Var1 "`nVar2 = " Var2 "`nVar3 = " Var3)
; or...
Notify("Var1 = " Var1)
Notify("Var2 = " Var2)
Notify("Var3 = " Var3)

- gwarble
Back to top
View user's profile Send private message
aaffe



Joined: 17 May 2007
Posts: 941
Location: Germany - Deutschland

PostPosted: Mon Nov 23, 2009 10:41 am    Post subject: Reply with quote

I think it should be
scratch .= "Put Some Var_Name_Here: " . Put_Some_Var_Name_Here . "`n"
instead of
scratch := scratch . ....
Ok, this only is a little shorter, but shorter is better, I think.
sinkfaze wrote:
Nice concept, most users come here not knowing how to set their code up for debugging and this is a nice template.

Since you're well familiar with the concatenation operator you could use the continuation section style to concatenate multiple results rather than assigning the variable to itself plus concatenation each time:

Code:
if 0       ; set to 1 to debug
   {
   scratch := ""
   scratch :=  scratch . "Put_Some_Var_Name_Here: " . Put_Some_Var_Name_Here . "`n"
   . "Put_Some_Var_Name_Here: " . Put_Some_Var_Name_Here . "`n"
   . "Put_Some_Var_Name_Here: " . Put_Some_Var_Name_Here . "`n"
   
   MsgBox % "[debugging]  [line " . A_LineNumber . "]`n`n" . scratch
   }
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group