AutoHotkey Community

It is currently May 27th, 2012, 10:29 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 27 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: October 2nd, 2007, 12:25 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Quote:
is there an alternate to actual `n to designate end of line ???
What for? :?
Code:
chr(10)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 2nd, 2007, 1:20 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
I use this function for debuging for long time. It can output 3 different ways

Code:
;------------------------------------------------------------------
; Function: Trace
;           Debug helper
;
; Remarks:
;   There are 3 trace types: _f_, _d_, _t_
;       _f_ - string will be appended at the end of the file trace.log
;       _d_ - string will be ouput using OutputDebug
;       _t_ - string will be output using Tooltip. This type has 1 parameter
;             which is number of history lines to keep
;
; By default _Trace() works in _f_ mode. To change the mode call function
; with first parameter specifying new mode:
;>      Trace("_t_", 4)    ;switch to tooltip mode, use 4 history lines
;
; You can enter up to 6 parameters. They will be displayed on single line
; between "|" separator
;
; Set global variable _trace to false to desable tracing
;
; Example:
;>      _trace := true,  Trace("_t_")       ;set at start of the script
;>      Trace(1, "some data", 3, 4, 5, 6)
;
Trace( pMsg0, pMsg1="", pMsg2="", pMsg3="", pMsg4="", pMsg5="", pMsg6="" ){
    local msg, time
    static type :="_f_", ttip, tcnt=1

    If !_trace
        return

    time := A_Hour ":" A_Min ":" A_Sec "," A_MSec " [" A_TickCount "]" "        "

    if pMsg0 in _d_,_f_,_t_
    {
     type := pMsg0
     if type = _t_
        if pMsg1 is Integer
            tcnt := pMsg1
     return
    }

    msg := pMsg0
    loop
        if (pMsg%A_Index% != "")
            msg .= " | " pMsg%A_Index%
        else break

    if (type = "_d_")   {
        OutputDebug, %msg%
        return
    }

    if (type = "_f_")   {
        FileAppend, %time%%msg%`n, %A_ScriptDir%\trace.log
        return
    }

    if (type = "_t_")   {
        if (tcnt > 1) {
            ttip := msg "`n" ttip
            StringReplace, ttip, ttip, `n, `n, UseErrorLevel
            if (ErrorLevel = tcnt)
                ttip := SubStr(ttip, 1, InStr(ttip, "`n", false, 0)-1)
            msg := ttip
        }
        Tooltip, %msg%, 0, 0, 19
        return
    }
}

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 2nd, 2007, 4:09 pm 
Offline

Joined: September 23rd, 2007, 4:16 pm
Posts: 140
Joy2DWorld wrote:
small suggests like:

why not call it DEBUG() ?
print and println are just ancient names borrowed from other languages. You can change it to whatever suits you.
Joy2DWorld wrote:
maybe include an optional Debug(text = "", pause = 0) {

option so that if pause // msgbox or pause ??
Possibly could add that, but if you want a message box, why not just use the message box command?
Code:
MsgBox, %str%


Joy2DWorld wrote:
and... maybe
a global DEBUGon? var...
I personally would probably not use this, but you could write a debug function to include with the original script that implements some of these features you want:
Code:
Debug(str, pause = 0) {
   global DebugOn
   if !DebugOn
      return
   if pause
      MsgBox, %str%
   else
      Print(str)
}


Last edited by Xander on October 2nd, 2007, 4:22 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 2nd, 2007, 4:14 pm 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
Quote:
Debug(str, pause = 0) {
if !DebugOn
likely needs a global dec,

Quote:
Debug(str, pause = 0) {
global DebugOn?
if !DebugOn?



and purpose of msgbox/pause is to allow freezing the script (where you choose), for debug help.. (like single step type thing),

and... reason to keep it in debug() is that with one global var set.. (at start of script) you can turn on debugging and off....

_________________
Joyce Jamce


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 2nd, 2007, 4:23 pm 
Offline

Joined: September 23rd, 2007, 4:16 pm
Posts: 140
Joy2DWorld wrote:
Quote:
Debug(str, pause = 0) {
if !DebugOn
likely needs a global dec

That is correct, correction has been made, thanks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 2nd, 2007, 4:57 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
I use message boxes, tool tips and ListVars for debugging. But this looks nice, thanks.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 3rd, 2007, 12:47 am 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
lexikos wrote:
Quote:
is there an alternate to actual `n to designate end of line ???
What for? :?


'quickhand' code notation... ex. "funct(x) { // if x < 0// return "Sorry!" // }"

instead of

funct(x) {
if x <0
return "Sorry!"
}

_________________
Joyce Jamce


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 3rd, 2007, 12:53 am 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
additional thought..
Code:
Debug(text  = "",version = 0, pause = "") {   ; use Debug? = 1  or Debug? = V{vers#} // if no vers #  shows with all vers,  pause for msgbox pause

   global Debug?
      static create, DebugOutput, vers
      
      if !Debug?
      return
      if pause = 1
         pause := text
         
         
      if !create {
         create =  1
         if regexmatch(Debug?,"i)\bV\s*(?<S>\d+(\.\d+)?)",ver)
            Debug? := regexreplace(Debug?,"i)\bV\s*[\w.]+")
      if (Debug? = 1) or  (debug = "")
         Debug? = w500 r4

      if !regexmatch(Debug?,"i)w\s*(?<E>\d+)",fromsid)
         fromside = 500
      gui, 98:default
        ;  Gui,  -Caption  ; leave on so can change size, etc..
         Gui, Margin, 0, 0
         gui, font, Cred S11, Veranda
         gui, color, ,EFEFD5
         Gui, Add, Edit, %Debug?% vDebugOutput    ;  ie,  debug contains w500 r4  or whatever!

      x := A_ScreenWidth - #(fromside)
         Gui, Show, +resize  +maximizebox NoActivate x%x% y%y%
      gui, 1:default 

      } 

      if (version and vers and (version < vers))
         return


idea to make the debug() VERSION based, so

debug("var PPr looks like :" PPr,2) for ver2
debug( a_linenumber "> " otherfunc(xx),2.1)


and setting at script top, Debug? = v2.1

so all lower version debugs are auto-killed....


ie... only get debugs you need for RELEVANT bug... type thing..


edit: (\.\d+)? added to \d+ to allow for dec'd numerics of vers... actually could just as well be non-numeric but... whatever...floats...

_________________
Joyce Jamce


Last edited by Joy2DWorld on October 3rd, 2007, 4:13 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 3rd, 2007, 1:37 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Joy2DWorld wrote:
lexikos wrote:
Quote:
is there an alternate to actual `n to designate end of line ???
What for? :?


'quickhand' code notation... ex. "funct(x) { // if x < 0// return "Sorry!" // }"

instead of

funct(x) {
if x <0
return "Sorry!"
}
Ah, no. I'm sure it has been suggested before, though. The closest you could come would be using comma , to put multiple expressions on the same line, and using ?: instead of if.
Code:
funct(x) {
  return x<0 ? "Sorry!" : ""
}
The following isn't possible, since return is a command:
Code:
x += 1, return x<0 ? "Sorry!" : ""
('return' is interpreted as a variable.)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 3rd, 2007, 3:11 am 
Offline

Joined: September 23rd, 2007, 4:16 pm
Posts: 140
Joy2DWorld wrote:
idea to make the debug() VERSION based, so

[...]

Sounds like you may want to go with one of the other debugging options posted. No need to reinvent the wheel :wink:

I am going to keep the OP version as is... the last thing I want is a buggy debugger :shock:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 3rd, 2007, 4:40 pm 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
@Xander,

thanks again for GREAT tool !!!!


have been using with version based notices, and *W*W* wow... it sure makes life easier... as many private msgs as desired ... then when have nailed down the issue, simply upgrade the version # tag at top of script and... silence...

no external progs to open... all clean and simple!

_________________
Joyce Jamce


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 3rd, 2009, 4:24 am 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
An alternative comments section...

Code:
;------------------------------------------------------------------
; Function: Trace
;           Debug helper
;
;
; Usage: Trace("_f_"|"_d_"|"_t_" [, HistoryLines])      eg Trace("_t_", 4)
;        Trace(Msg0 [, Msg1, Msg2, Msg3, Msg4, Msg, Msg6])   eg Trace(1, "some data", 3, 4, 5, 6)
;
;
; More Usage:
;
;   -------------------------------
;    _trace := true,  Trace("_t_")          ################## START OF SCRIPT ###################
;   -------------------------------
;
;    Enable/disable debugging...
;           Set global variable _trace to false to disable tracing
;   
;    Mode selection...
;      There are 3 trace types: _f_, _d_, _t_
;        _f_ - string will be appended at the end of the file trace.log
;        _d_ - string will be ouput using OutputDebug
;        _t_ - string will be output using Tooltip. This type has 1 parameter
;              which is number of history lines to keep
;   
;      By default _Trace() works in _f_ mode. To change the mode call function
;      with first parameter specifying new mode:
;        Eg Trace("_t_", 4)    ;switch to tooltip mode, use 4 history lines
;
;   -----------------------------------
;    Trace(1, "some data", 3, 4, 5, 6)      ################## MIDDLE OF SCRIPT ##################
;   -----------------------------------
;
;   Where want to debug
;
;   Displaying messages/variables...
;     You can enter up to 6 parameters. They will be displayed on single line
;     between "|" separator
;
;   ---------------------------
;    #Include <path>\Trace.ahk              ################### END OF SCRIPT ####################
;   ---------------------------
;
;   Where subroutines are located
;
;   Or put copy of function here
;
;


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 27 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 17 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group