Jump to content

GUI version of Tail


Recommended Posts

Try this, this works for me, continously generating tail until i click the button to stop.

#include <File.au3>
#include <Array.au3>
#include <GUIConstants.au3>

$s_FileName = "test.txt"
Dim $a_Lines
Dim $read = True

GUICreate( "Tail Function - Continuous File Monitoring", 200, 200 )
$stop = GUICtrlCreateButton( "Click here to end file monitoring.", 10, 10, 180, 180, "0x0700" )
GUISetState( @SW_SHOW )

While $read = True    
    _FileReadToArray( $s_FileName, $a_Lines )

    $i_tailLines = 5

    $a_Tail = _Tail( $i_tailLines, $a_Lines )

#    _ArrayDisplay( $a_Tail, "" )
    
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Or $msg = $stop Then
        $read = False
    EndIf
WEnd

Func _Tail( $i_numTail, $a_readLines )
    #calculate which line to end on
    $endLine = UBound( $a_readLines ) - $i_numTail
    
    Dim $a_tailLines[ $i_numTail ]
        
    For $iter = UBound( $a_readLines ) - 1 To $endLine Step -1
        $a_tailLines[ $iter - $endLine ] = $a_readLines[ $iter ]
    Next
    
    Return $a_tailLines        
EndFunc

Hope this helps.

Thanks for the effort, but i get the following error when i try to beta compile it:

(36) : ==> Array variable subscript badly formatted.: 
$a_tailLines[ $iter - $endLine ] = $a_readLines[ $iter ] 
$a_tailLines[ $iter - $endLine ] = $a_readLines[ ^ ERROR

I'm wondering, what version of Autoit Beta are you using (i'm using the latest, 133 i think it is).

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Link to comment
Share on other sites

Forgot to warn you, this reads from "test.txt" and includes NO ERROR CHECKING. Please make sure you have a test.txt file in the script dir or you change the file name in the script to some file in the script dir. This is whats causign the error.

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Link to comment
Share on other sites

Forgot to warn you, this reads from "test.txt" and includes NO ERROR CHECKING. Please make sure you have a test.txt file in the script dir or you change the file name in the script to some file in the script dir. This is whats causign the error.

Yes I saw that. i do have the test.txt file on the same folder as the script.

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Link to comment
Share on other sites

Ok i think i got it.

Thanks to everyone who's helped!

#include <File.au3>
#include <GUIConstants.au3>
#Include <GuiEdit.au3>
Opt("GUIOnEventMode", 1)
Opt('GUICloseOnESC', 1)

;           Start GUI Window and Elements creation -->
$W_size_l = 700
$Wsize_h =400
$mainWindow = GUICreate("Tails",$W_size_l,$Wsize_h)         
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")             
GUISetState(@SW_SHOW)

GUICtrlCreateLabel("Please select the file you want to tail", 30, 10)  

$fileopenButton = GUICtrlCreateButton("Open File",30, 40)
GUICtrlSetOnEvent($fileopenButton, "FileopenButton")
                                                                            
$editControl = GUICtrlCreateEdit("",30,120, $W_size_l-60,   ($Wsize_h/3)*2,$WS_VSCROLL+ _ 
                                                             $ES_MULTILINE+$ES_AUTOVSCROLL+$ES_READONLY)
$InputControl = GUICtrlCreateinput("Choose file",30,80, 300, 20 )
$linecountcontrol = GUICtrlCreateInput("Lines : ",360,80,150,20,$ES_READONLY)


while 1

    Tailit()
    Sleep(100)
WEnd

func Tailit()
    
;           Function Environment settings   -->
    $error =0
    $initial = 0
    $file = ControlGetText("Tails","",$InputControl)
    

    $count = _FileCountLines($file)
    $scan= filereadline($file, $count)
    If $initial = 0 then 
        $initial = 1
    $file_contents = ""
    for $x =1 to $count
        $file_contents = $file_contents  & filereadline($file, $x)& @CRLF
    next
    GUICtrlSetData($editControl, $file_contents)
    GUICTrlSetData($linecountcontrol, "Lines : " &$count)
    _GUICtrlEditLineScroll ($editControl, 0, $count)
    EndIf

EndFunc 

func FileopenButton()
$selected_file = FileOpenDialog("Open",@ScriptDir,"Text Files (*.*)")
GUICtrlSetData($InputControl, $selected_file)
Global  $openfile = FileOpen($selected_file,0)
EndFunc

Func CLOSEClicked()
    fileclose($openfile)
     Exit
EndFunc

I'll post it in scripts and scraps when im done cleaning it up and optimizing it.

-L

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

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...