iceberg Posted August 26, 2006 Share Posted August 26, 2006 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. Link to comment Share on other sites More sharing options...
Xenobiologist Posted August 26, 2006 Share Posted August 26, 2006 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 ... 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 Link to comment Share on other sites More sharing options...
xcal Posted August 26, 2006 Share Posted August 26, 2006 (edited) Lots of different ways to tackle his one. #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 Edited August 26, 2006 by xcal How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
theguy0000 Posted August 26, 2006 Share Posted August 26, 2006 (edited) Lots of different ways to tackle his one. #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^ Edited August 26, 2006 by theguy0000 The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN Link to comment Share on other sites More sharing options...
xcal Posted August 26, 2006 Share Posted August 26, 2006 (edited) Even better...except I think you meant to end that with a Next, and $num To 0 should be $num To 1. No line 0 in a text. Edited August 26, 2006 by xcal How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
theguy0000 Posted August 26, 2006 Share Posted August 26, 2006 right. thanks The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN Link to comment Share on other sites More sharing options...
iceberg Posted August 26, 2006 Author Share Posted August 26, 2006 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. Link to comment Share on other sites More sharing options...
amanda089 Posted August 26, 2006 Share Posted August 26, 2006 #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). Link to comment Share on other sites More sharing options...
xcal Posted August 26, 2006 Share Posted August 26, 2006 I tested it for kicks, and it works perfectly. If you want to make it return to the bottom of the file after it hits the top, add... If $num - $readlines < 1 Then $readlines = 0 ...as the first line in the function. How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
iceberg Posted August 27, 2006 Author Share Posted August 27, 2006 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. Link to comment Share on other sites More sharing options...
xcal Posted August 27, 2006 Share Posted August 27, 2006 (edited) $readlines += 1 is just a simplier way of doing $readlines = $readlines + 1. Check out "Operators" in the help file for a list. Edited August 27, 2006 by xcal How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
iceberg Posted August 27, 2006 Author Share Posted August 27, 2006 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. Link to comment Share on other sites More sharing options...
Richard Robertson Posted August 27, 2006 Share Posted August 27, 2006 Just curious, why are you reading a file backwards? Link to comment Share on other sites More sharing options...
xcal Posted August 27, 2006 Share Posted August 27, 2006 (edited) expandcollapse popup#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 August 27, 2006 by xcal How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
iceberg Posted August 27, 2006 Author Share Posted August 27, 2006 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. Link to comment Share on other sites More sharing options...
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