daniel02 Posted October 10, 2009 Posted October 10, 2009 Hi all, I would like to write a logfile with time and date entries and display the last 5 entries in my gui like a unix "tail -f" which means new logentries will be shown in that list and the oldest one disaper. My Problem.. I have no Idea how to do it I am allready writing from every function an Information in my gui but you can just see the current function which is executed: The gui ####### GUICtrlCreateLabel("Current Function/Debug:", 5, 150) $CurrentFunction = GUICtrlCreateInput("No Function", 5, 170, 125, 20) In functions ############# If $DisplayCurrentFunction = 1 Then GUICtrlSetData($CurrentFunction, " Scanning. ") What I saw from reading here is that I have to write the logfile with Fileopen so I would guess: $file = FileOpen($logFile, 1) ; $tCur = _Date_Time_GetLocalTime() FileWriteLine($file, _Date_Time_SystemTimeToDateTimeStr($tCur) & "|" & $DisplayCurrentFunction FileClose($file) I hope this is correct. But how can I now show the 5 entires in the gui? Thanks Daniel
daniel02 Posted October 10, 2009 Author Posted October 10, 2009 one update. What I did so far: GUICtrlCreateLabel("Current Function/Debug:", 5, 150) $CurrentFunction = GUICtrlCreateInput("No Function", 5, 170, 125, 20) GUICtrlSetBkColor(-1, 0x00ff00) GUICtrlCreateLabel("Last Function/Debug:", 5, 200) $logfile = FileOpen(@ScriptDir & "\HelpMe.log", 0) $read1 = FileReadLine($logfile,-1) $LastFunction1=GUICtrlCreateInput($read1, 5, 220, 200, 20) GUICtrlSetBkColor(-1, 0x00ff00) Func writelogfie() If $DisplayCurrentFunction = 1 Then $file = FileOpen(@ScriptDir & "\HelpMe.log", 1) ; $tCur = _Date_Time_GetLocalTime() FileWriteLine($file, _Date_Time_SystemTimeToDateTimeStr($tCur) & " " & GUICtrlRead($CurrentFunction)) FileClose($file) $read1 = FileReadLine($logfile,-1) GUICtrlSetData($LastFunction1, $read1) EndIf But this is only working for the Last Entry in the logfile. Not for the last 5.
nfaustin Posted October 11, 2009 Posted October 11, 2009 (edited) Try to use _ArrayPush(). Save the last 5 entry to an array which contains only 5 items Func writelogfie() Dim $Test[5] = [1,2,3,4,5] If $DisplayCurrentFunction = 1 Then $file = FileOpen(@ScriptDir & "\HelpMe.log", 1) ; $tCur = _Date_Time_GetLocalTime() FileWriteLine($file, _Date_Time_SystemTimeToDateTimeStr($tCur) & " " & GUICtrlRead($CurrentFunction)) FileClose($file) $file = FileOpen(@ScriptDir & "\HelpMe.log") ; Read in lines of text until the EOF is reached While 1 _ArrayPush($Test, FileReadLine($file)) If @error = -1 Then ExitLoop Wend FileClose($file) ; Display all items on array to Input box for $i = 0 to 4 GUICtrlSetData($LastFunction1, $Test[$i],1) Next EndIf Edit: not tested. At least given you an idea. Edited October 11, 2009 by nfaustin [font="Palatino Linotype"][size="2"]*** The information contained in this post should be considered and certified WORKS ON MY MACHINE ***[/size][/font][font="Palatino Linotype"][size="2"] [/size][/font]
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