Sign in to follow this  
Followers 0
JohnMC

Logging/External Error notification

7 posts in this topic

#1 ·  Posted (edited)

Im not sure what to call this but basicly im looking for the best way to help debug/report errors in my script or even just verbose, i need the script to continue on as normal (failure or otherwise) but output a message to a console style window, or even just a msgbox that doesnt hult the script (in the case of error). i think that seeing as i have no idea what this might be called, is probably the reason why my searches have turned up nothing... thanks for any help!!

Edited by JohnMC

Share this post


Link to post
Share on other sites



Im not sure what to call this but basicly im looking for the best way to help debug/report errors in my script or even just verbose, i need the script to continue on as normal (failure or otherwise) but output a message to a console style window, or even just a msgbox that doesnt hult the script (in the case of error). i think that seeing as i have no idea what this might be called, is probably the reason why my searches have turned up nothing... thanks for any help!!

I like _FileWriteLog() because it automatically time stamps entries in the log.

ToolTip(), TrayTip(), or SplashTextOn() are good for GUI text messages that don't block the script. Beyond that you would be creating your own popup GUI.

:)


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

#3 ·  Posted (edited)

I like _FileWriteLog() because it automatically time stamps entries in the log.

ToolTip(), TrayTip(), or SplashTextOn() are good for GUI text messages that don't block the script. Beyond that you would be creating your own popup GUI.

:)

i just put this together:

func _svl($text,$p1=0)
    if NOT IsDeclared("SVLGUIC") then GLOBAL $SVLGUIC="RESET"
    
    $title=@ScriptName&"/"&@AutoItPID
    
    $GW=550
    $GH=300
    
    if $SVLGUIC="RESET" then
        GLOBAL $SVLGUIC = GUICreate($title,$GW,$GH,-1,-1)
        GLOBAL $SVLEDIT = GUICtrlCreateEdit("Created By "&@AutoItPID, 0, 0, 550, 280)
        GUICtrlSetFont(-1, 8, 400, 0, "Fixedsys")
        GUICtrlSetColor(-1, 0x000000)
        GUICtrlSetBkColor(-1, 0xFFFFFF)
        GLOBAL $SVLEXIT = GUICtrlCreateButton("Exit",0,281,550,19)
        GUISetState(@SW_SHOW)
    endif

    if Opt("GUIOnEventMode")=1 Then 
        GUICtrlSetOnEvent ($SVLEXIT,"_delete_svl")
        GUICtrlSetOnEvent (-3,"_delete_svl")
    EndIf
    
    $data=GUICtrlRead($SVLEDIT)
    $data=stringtrimleft($data,StringInStr($data,@CRLF,-1,-50));50 lines max on screen
    
    If $p1>=4 Then
        $p1=$p1-4
        WinSetOnTop ($title,"",1)
    EndIf
    If $p1>=2 Then
        $p1=$p1-2
        WinSetTrans ($title,"",100)
    EndIf
    if $p1>=1 then 
        $p1=$p1-1
        $newdata=$data&" "&$text
    Else
        $newdata=$data&@CRLF&@HOUR&":"&@MIN&":"&@SEC&"> "&$text
    EndIf
    
    
    GUICtrlSetData ($SVLEDIT,"")
    GUICtrlSetData ($SVLEDIT,$newdata,1)
    
    $msg=GUIgetmsg($SVLGUIC)
        if $msg=$SVLEXIT then _delete_svl()
        If $msg=-3 Then _delete_svl()
endfunc
func _delete_svl()
    if NOT IsDeclared("SVLGUIC") then GLOBAL $SVLGUIC=""
    GUIDelete ($SVLGUIC)
    GLOBAL $SVLGUIC="RESET"
endfunc

i cant say its awesome but it works for me, of corse to maintain it as a function, the 'exit' button isnt reliable unless you use gui events in the script, any idea to make this any better?

Edited by JohnMC

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

i just put this together:

CODE
func _svl($text,$p1=0)

if NOT IsDeclared("SVLGUIC") then GLOBAL $SVLGUIC="RESET"

$title=@ScriptName&"/"&@AutoItPID

$GW=550

$GH=300

if $SVLGUIC="RESET" then

GLOBAL $SVLGUIC = GUICreate($title,$GW,$GH,-1,-1)

GLOBAL $SVLEDIT = GUICtrlCreateEdit("Created By "&@AutoItPID, 0, 0, 550, 280)

GUICtrlSetFont(-1, 8, 400, 0, "Fixedsys")

GUICtrlSetColor(-1, 0x000000)

GUICtrlSetBkColor(-1, 0xFFFFFF)

GLOBAL $SVLEXIT = GUICtrlCreateButton("Exit",0,281,550,19)

GUISetState(@SW_SHOW)

endif

if Opt("GUIOnEventMode")=1 Then

GUICtrlSetOnEvent ($SVLEXIT,"_delete_svl")

GUICtrlSetOnEvent (-3,"_delete_svl")

EndIf

$data=GUICtrlRead($SVLEDIT)

$data=stringtrimleft($data,StringInStr($data,@CRLF,-1,-50));50 lines max on screen

If $p1>=4 Then

$p1=$p1-4

WinSetOnTop ($title,"",1)

EndIf

If $p1>=2 Then

$p1=$p1-2

WinSetTrans ($title,"",100)

EndIf

if $p1>=1 then

$p1=$p1-1

$newdata=$data&" "&$text

Else

$newdata=$data&@CRLF&@HOUR&":"&@MIN&":"&@SEC&"> "&$text

EndIf

GUICtrlSetData ($SVLEDIT,"")

GUICtrlSetData ($SVLEDIT,$newdata,1)

$msg=GUIgetmsg($SVLGUIC)

if $msg=$SVLEXIT then _delete_svl()

If $msg=-3 Then _delete_svl()

endfunc

func _delete_svl()

if NOT IsDeclared("SVLGUIC") then GLOBAL $SVLGUIC=""

GUIDelete ($SVLGUIC)

GLOBAL $SVLGUIC="RESET"

endfunc

i cant say its awesome but it works for me, of corse to maintain it as a function, the 'exit' button isnt reliable unless you use gui events in the script, any idea to make this any better?
I don't think it's a good idea to try to handle both environments where EventMode is used and not. Pick one and code for it. All my real work scripts use EventMode. The exit button is redundant. By default the AutoIt GUI has the close button 'X' at the top right corner, so all you needed was:
GuiSetOnEvent($GUI_EVENT_CLOSE, "_delete_svl", $SVLGUIC)

:)

Edited by PsaltyDS

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

I don't think it's a good idea to try to handle both environments where EventMode is used and not. Pick one and code for it. All my real work scripts use EventMode. The exit button is redundant. By default the AutoIt GUI has the close button 'X' at the top right corner, so all you needed was:

GuiSetOnEvent($GUI_EVENT_CLOSE, "_delete_svl", $SVLGUIC)

:)

good point...

even of i set it up like this?:

if Opt("GUIOnEventMode")=1 Then 
        GUICtrlSetOnEvent ($SVLEXIT,"_delete_svl")
        GUICtrlSetOnEvent (-3,"_delete_svl")
    Elseif GUIgetmsg($SVLGUIC)=-3
        _delete_svl()
    EndIf

i had another question, how improper is it to use the value of a constant in place of the constant it self, as in If $msg=-3 Then _delete_svl() i just didnt want this function to need any includes

Share this post


Link to post
Share on other sites

good point...

even of i set it up like this?:

if Opt("GUIOnEventMode")=1 Then 
        GUICtrlSetOnEvent ($SVLEXIT,"_delete_svl")
        GUICtrlSetOnEvent (-3,"_delete_svl")
    Elseif GUIgetmsg($SVLGUIC)=-3
        _delete_svl()
    EndIf

i had another question, how improper is it to use the value of a constant in place of the constant it self, as in If $msg=-3 Then _delete_svl() i just didnt want this function to need any includes

Your ElseIf condition to check the GUI message is done ONCE, not in a loop. So unless you can hit the exit on exactly the right millisecond, the message will be lost among any other messages that occur. It just doesn't make sense. Write your scripts in EventMode, or don't, but stop trying to mix them.

As for the constants, using the literal value is perfectly valid. It's just easier to use the UDF files if there are more than two or three to keep track of.

:)


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

Your ElseIf condition to check the GUI message is done ONCE, not in a loop. So unless you can hit the exit on exactly the right millisecond, the message will be lost among any other messages that occur. It just doesn't make sense. Write your scripts in EventMode, or don't, but stop trying to mix them.

As for the constants, using the literal value is perfectly valid. It's just easier to use the UDF files if there are more than two or three to keep track of.

:)

thanks for the help, and i understand what your saying and why your saying it, but i obviously have a goal to handle both, this is just code to help me build scripts and would rarely be used in one i would use in a distribution. i just want a simple function i can add into a toubled loop or something to help me figure out an issue, and i havnt made a decision one event driven untill i get to that part, so i never know what i might have to deal with.

you saying that however made me realize using a checkbox would get the job done, in combination with a call to _svl() and no parameters in my loops if i need it

so i ended up with:

func _svl($text="",$p1=0);$text=Text to display  $p1= 1 for continue on previous line, 2 for transparent, 4 for always on top  (May add together)
    if NOT IsDeclared("SVLGUIC") then GLOBAL $SVLGUIC="RESET"
    
    $title=@ScriptName&"/"&@AutoItPID

    if $SVLGUIC="RESET" then
        GLOBAL $SVLGUIC = GUICreate($title,550,300)
        GLOBAL $SVLEDIT = GUICtrlCreateEdit("Created By "&@AutoItPID, 0, 0, 550, 280)
        GUICtrlSetFont(-1, 8, 400, 0, "Fixedsys")
        GUICtrlSetColor(-1, 0x000000)
        GUICtrlSetBkColor(-1, 0xFFFFFF)
        Global $SVLEXIT = GUICtrlCreateCheckbox("Close On Next Update", 204, 280, 129, 17)
        GUISetState(@SW_SHOW)
    endif
    

    If $p1>=4 Then
        $p1=$p1-4
        WinSetOnTop ($title,"",1)
    EndIf
    If $p1>=2 Then
        $p1=$p1-2
        WinSetTrans ($title,"",100)
    EndIf
    
    If $text<>"" Then
        $data=GUICtrlRead($SVLEDIT)
        $data=stringtrimleft($data,StringInStr($data,@CRLF,-1,-50));50 lines max on screen
    
        if $p1>=1 then 
            $p1=$p1-1
            $newdata=$data&" "&$text
        Else
            $newdata=$data&@CRLF&@HOUR&":"&@MIN&":"&@SEC&"> "&$text
        EndIf
        GUICtrlSetData ($SVLEDIT,"")
        GUICtrlSetData ($SVLEDIT,$newdata,1)
    EndIf
    
    if Opt("GUIOnEventMode")=1 Then GUICtrlSetOnEvent (-3,"_delete_svl")
    If GUICtrlRead($SVLEXIT)=1 Then _delete_svl()
endfunc
func _delete_svl()
    if NOT IsDeclared("SVLGUIC") then GLOBAL $SVLGUIC=0
    GUIDelete ($SVLGUIC)
    GLOBAL $SVLGUIC="RESET"
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  
Followers 0