Jump to content

Logging Window


Recommended Posts

Greetings,

I want to keep a running log of what my script is doing on the screen, perhaps in a scrollable window that I can post strings to that are prefaced with the output of _NowCalc(). I know I can figure out how to do it with time but if there is a working example I can start with that would be a great leg up in development and time savings.

Thanks,

jh

Link to comment
Share on other sites

is this what you had in mind?

#include <GUIConstants.au3>
#include <Date.au3>

Opt("GUIOnEventMode", 1)
$Log_GUI = GUICreate("Log", 385, 395, 258, 190)
GUISetOnEvent($GUI_EVENT_CLOSE, "Log_Close")
$Log_Edit = GUICtrlCreateEdit("", 8, 8, 369, 377, BitOR($ES_AUTOVSCROLL,$ES_READONLY,$ES_WANTRETURN,$WS_VSCROLL))
GUISetState(@SW_SHOW)

While 1
    Sleep(100)
WEnd
        
Func Log_Close()
    Exit
    ;could be 'GUISetState(@SW_HIDE, $Log_GUI)' if you do not want to exit the script
EndFunc


Func _WriteLineToLog($Log_String_WriteLineToLog)
    GUICtrlSetData($Log_Edit, _NowCalc() & " - " & $Log_String_WriteLineToLog & @CRLF, 1)
endfunc

you can write to the log by using the function "_WriteLineToLog" in the format of "WriteLineToLog("Any string/string variable here")". Hide the GUI by using "GUISetState(@SW_HIDE, $Log_GUI)"

Link to comment
Share on other sites

Yes, this is most excellent!

Many thanks. This fits my idea of code re-use: take good code that someone else has debugged, learn from it, and build on it.

BTW, why does _WriteLineToLog start w/ an underscore? Is this some type of convention of which I am not yet aware?

jh

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...