Jump to content
Sign in to follow this  
iceberg

FileOpen Func

Recommended Posts

Hi,

How do I use the function to read file lines from last line up to first line?

Thanks.


mouse not found....scroll any mouse to continue.

Share this post


Link to post
Share on other sites

Hi,

How do I use the function to read file lines from last line up to first line?

Thanks.

Hi,

you can read it into an array with _FileReadToArray and then start from the back Ubound() -1 ...

:P

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Lots of different ways to tackle his one. :P

#include <File.au3>

$i = _FileCountLines("test.txt")
While 1
    $line = FileReadLine("test.txt", $i)
    MsgBox(0, "", $line)
    $i -= 1
    If $i = 0 Then ExitLoop
WEnd
oÝ÷ Ûú®¢×¨®È¦¦XÊ+ZºÚ"µÍÚ[ÛYH Ñ[K]LÉÝÂÌÍÛ[HHÑ[PÛÝ[[Ê   ][ÝÝÝ    ][ÝÊBÜ   ÌÍÚOIÌÍÛ[HÈHÝLBIÌÍÛ[HH[TXY[J ][ÝÝÝ    ][ÝË  ÌÍÚJBSÙÐÞ
    ][ÝÉ][ÝË    ÌÍÛ[JB^

:nuke:

Edited by theguy0000

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites

right. thanks :P


The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites

hi thanks alot for all the replies.

another one more questions pls...if lets say i have a GUI button.

I want the func to read the text file line by line, upwards, by only pressing the GUI button.

meaning when i press the button, it reads and displays only the last line. when i press the button again, it displays the second last line and so on....

pls help. thanks.


mouse not found....scroll any mouse to continue.

Share this post


Link to post
Share on other sites

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

$num = _FileCountLines("test.txt")
$readlines = 0

; == GUI generated with Koda ==
$Form1 = GUICreate("AForm1", 622, 441, 192, 125)
$Edit1 = GUICtrlCreateEdit("", 0, 0, 621, 81, -1, $WS_EX_CLIENTEDGE)
GUICtrlSetData($Edit1, "AEdit1")
$Button1 = GUICtrlCreateButton("Read Next Line", 10, 85, 146, 36)
GUISetState(@SW_SHOW)
While 1
    $msg = GuiGetMsg()
    Select
        Case $msg = $Button1
            readline()
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case Else
            ;;;;;;;
    EndSelect
WEnd
Exit

func readline()
    $line = FileReadLine("test.txt", $num - $readlines)
    GUICtrlSetData($Edit1, $line, "")
    $readlines += 1
EndFunc

Untested, but it should work (I believe).

Share this post


Link to post
Share on other sites

wow excellent!

thanks a million xcal.

just wondering something about the expressions which i don't understand.

why is it "$readlines += 1" and not "$readlines = +1"

thanks.


mouse not found....scroll any mouse to continue.

Share this post


Link to post
Share on other sites

ok got tat. how wd the function be if i wanna go "Read Previous Line"

func readline2()
    $line = FileReadLine("test.txt", $num - $readlines)
    GUICtrlSetData($Edit1, $line, "")
    $readlines -= 1
EndFunc

the above did work to a certain extent.


mouse not found....scroll any mouse to continue.

Share this post


Link to post
Share on other sites

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

$num = _FileCountLines("test.txt")
$readlines = -1

; == GUI generated with Koda ==
$Form1 = GUICreate("AForm1", 622, 441, 192, 125)
$Edit1 = GUICtrlCreateEdit("", 0, 0, 621, 81, -1, $WS_EX_CLIENTEDGE)
GUICtrlSetData($Edit1, "AEdit1")
$Button1 = GUICtrlCreateButton("Read Next Line", 10, 85, 146, 36)
$Button2 = GUICtrlCreateButton("Read Previous Line", 166, 85, 146, 36)
GUISetState(@SW_SHOW)

While 1
    $msg = GuiGetMsg()
    Select
        Case $msg = $Button1
            readline()
        Case $msg = $Button2
            prevline()
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case Else
            ;;;;;;;
    EndSelect
WEnd

func readline()
    $readlines += 1
    If $num - $readlines < 1 Then $readlines = 0
    $line = FileReadLine("test.txt", $num - $readlines)
    GUICtrlSetData($Edit1, $line, "")
EndFunc

func prevline()
    $readlines -= 1
    If $num - $readlines > $num Then $readlines = $num - 1
    $line = FileReadLine("test.txt", $num - $readlines)
    GUICtrlSetData($Edit1, $line, "")
EndFunc

Edited by xcal

Share this post


Link to post
Share on other sites

thanks once again xcal!

Icekirby1, i am creating a log text file using my program. just wanna use the Forward and Backward buttons to read the log file entries.

thanks.


mouse not found....scroll any mouse to continue.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...