Jump to content
Sign in to follow this  
scruiD

Read textfile to label, how to autoscroll to end

Recommended Posts

scruiD

Hi there,

I am new here and were looking for a solution but did not find in my combination so I assume my code or logic isn't the best.

short: I have a logfile written on the harddrive, that I do read to an label and if the labelcontent has changed (logfile has new lines) it refreshes the label. My Problem is, when the textfile is too big, it does not display the end of the textfile, how can I make it happen that it always displays the end of the textfile? What I have so far (Sorry if too much or too stupid, I am still learning :)

#include <GuiConstantsEx.au3>

#include <ButtonConstants.au3>

#include <TabConstants.au3>

#include <WindowsConstants.au3>

#include <StaticConstants.au3>

#include <File.au3>

#include <Constants.au3>

#include <GUIConstantsEx.au3>

; Definitionen

Dim $Logfile_Displayed

$GFX_Splash=FileFindFirstFile("C:\splash.jpg")

$GFX_Warning=FileFindFirstFile("C:\warning.jpg")

$GUI_Label=GUICtrlCreatelabel("", 10, 300, 620, 200)

Splashscreen()

GUI_APP()

While 1

if GUIGetMsg() = -3 then Exit

GUI_Update()

WEnd

func GUI_Update()

$Logfile=("C:\update.log")

$Logfile_Open=FileOpen ($Logfile,0)

$Logfile_Read=FileRead($Logfile_Open)

FileClose($Logfile)

FileClose($Logfile_Open)

If $Logfile_Read <> $Logfile_Displayed then

GUICtrlSetFont(-1, 11)

GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

GUICtrlCreatelabel($Logfile_Read, 30, 100, 480, 270)

$Logfile_Displayed=$Logfile_Read

GUISetState(@SW_SHOW)

Sleep(4000)

EndIf

FileFlush($Logfile_Read)

EndFunc

func Splashscreen()

If FileExists($GFX_Splash) Then

SplashImageOn("UpdateLog for incoming files", $GFX_Splash, 640, 480)

Sleep(3000)

SplashOff()

EndIf

EndFunc

func GUI_APP()

GuiCreate("Log", 640, 480)

GuiCtrlCreateTab(1, 0, 640, 480)

GuiCtrlCreateTabItem("Status")

GUICtrlCreateGroup("Update Progress", 5, 25, 520, 410)

EndFunc

Thx for any help :mellow:

Share this post


Link to post
Share on other sites
scruiD

I'd advise you to use a read only edit control instead of a label.

Perfect! Thx! Exactly what I was looking for - just a bit confused about to use Input for an output :mellow:

Share this post


Link to post
Share on other sites
scruiD

Okay I have a scroll bar that I can manually scroll down to the end ot he log so I see the last logfile updates then. Is there a way to autoscroll to bottom. Find a function like this only for a listview, but that I won't have - just simple, show the most current content of the textfile written on the end of it. It seems there is no autoscroll builtin for it? :mellow:

Share this post


Link to post
Share on other sites
sebgg

Okay I have a scroll bar that I can manually scroll down to the end ot he log so I see the last logfile updates then. Is there a way to autoscroll to bottom. Find a function like this only for a listview, but that I won't have - just simple, show the most current content of the textfile written on the end of it. It seems there is no autoscroll builtin for it? :mellow:

just a thought but,

MouseWheel ( "down" ,500 )

add that after each time it writes to the gui?

otherwise I have no idea sorry.

sebs


GC - Program to rapidly manipulate DNA SequencesRotaMol - Program to measure Protein Size

Share this post


Link to post
Share on other sites
smartee

hi scruiD,

Try using _GUICtrlEdit_AppendText(), upon adding text to an edit control, it automatically scrolls to the bottom, here is a little demo :mellow:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>

$Form1 = GUICreate("Demo1", 600, 200)
$Edit1 = GUICtrlCreateEdit("", 10, 10, 580, 180, BitOR($ES_AUTOVSCROLL, $WS_VSCROLL, $ES_READONLY))
GUISetState(@SW_SHOW)

Global $iLineNum = 1
AdlibRegister("_AppendLine", "250")

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

    EndSwitch
WEnd

Func _AppendLine()
    _GUICtrlEdit_AppendText($Edit1, "Line #" & $iLineNum & @CRLF)
    $iLineNum += 1
EndFunc   ;==>_AppendLine

Hope this helps, :)

-smartee

Edit: Added more info, example.

Edited by smartee

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.