DigDeep

Copy log file lines into GUI Lable

6 posts in this topic

Not sure what am I doing wrong here...

I have a GUI with label in which I want to display the log file line by line.

If line 1 is written the same should also display in the GUI Lable.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>

Global $LogLastLine, $LogFile, $LogDIR
Global $Run = 9999

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 341, 611, 1021, 326)
$Label1 = GUICtrlCreateLabel("", 8, 8, 324, 545)
$Run = GUICtrlCreateButton("Run", 128, 568, 75, 25)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Run
            LogPath() ; LogPath

    EndSwitch
WEnd

Func LogPath() ; LogPath
$LogDIR = "C:\Temp\Test"
DirCreate($LogDIR)
$LogFile = $LogDIR & "\Test.log"

        _FileCreate($LogFile)

        If FileExists($LogFile) Then
            GetLogLastLine() ; Read last line of the log file

            _FileWriteLog($LogFile, "Log Line 1")
            $Label2 = GUICtrlCreateLabel($LogLastLine, 10, 48, 316, 17)

            _FileWriteLog($LogFile, "Log Line 2")
            $Label3 = GUICtrlCreateLabel($LogLastLine, 10, 72, 316, 17)

            _FileWriteLog($LogFile, "Log Line 3")
            $Label4 = GUICtrlCreateLabel($LogLastLine, 16, 104, 316, 17)

; And this will go on till the activity completes and Log line ends...

        EndIf
EndFunc


Func GetLogLastLine() ; Read last line of the log file
DirCreate($LogDIR & "\New")

    FileCopy("C:\Temp\Test\Test.log", "C:\Temp\Test\New", 1)
    $FileOpen = FileOpen("C:\Temp\Test\New\Test.log", 0)

        For $i = 1 To _FileCountLines($FileOpen)
            $LogLastLine = FileReadLine($FileOpen, $i)
        Next
    FileClose($FileOpen)
EndFunc

 

Share this post


Link to post
Share on other sites



Use GUICtrlSetData instead of creating new labels everytime.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

@BrewManNH I got it via lables here but yes for every Log entry, I have to get a new lable created.

Can you please show me the GUICtrlSetData way if that will save me showing the log lines.

Another query is can I set the get the Lable set in such a way so that if a log line is lengthy enough, it will automatically display in multple lines in the lable instead of text crossing outside the lable as a single line?

 

I am correcting the query part here... I have tested and checked that the lengthy log lines automatically show up as 2nd line in the lable. The only issue is that it gets cut of in the 2nd line due to the height of the lable.

So yes, even though this is fixed I think you are one way correct. Either I have to find a way to get 1 single lable and show the lines that will not create an issue with the cut of texts or see how the GUICtrlSetData way works.

Can you help please?

Edited by DigDeep

Share this post


Link to post
Share on other sites

You should probably be using an Edit control and not a label for this.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Yep, used the GUICtrlCreateListView and it works pretty well.

But using the GUICtrlCreateListView way, if log line text is way too lengthy it shows in the same line and I have to expand the column manually to read complete statement. Is there a way I can restrict the GUICtrlCreateListView  screen to a particular width so that if a log line length is more than the width it will display in the next line?

So, if I take the example of _GUICtrlListView_SetColumnWidth, can I get the Line 2 show up in multiple lines instead of single line?

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    Local $idListview

    GUICreate("ListView Get Column Width", 400, 300)
    $idListview = GUICtrlCreateListView("Column 1", 2, 2, 394, 268)
    GUISetState(@SW_SHOW)
    _GUICtrlListView_SetColumnWidth($idListview, 0, 390)

GUICtrlCreateListViewItem("Line 1", $idListview)
GUICtrlCreateListViewItem("Line 2: The actors of 1812 have long since left the stage, their personal interests have vanished leaving no trace, and nothing remains of that time but its historic results.", $idListview) ; This is a Lengthy text example to show in multiple lines...
GUICtrlCreateListViewItem("Line 3", $idListview)


    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

 

Share this post


Link to post
Share on other sites

DigDeep,

You are better off with an edit control, as BrewmanNH suggested.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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