myspacee 1 Posted July 16, 2011 Hello, in a cicle i store in a Var some text, eg: juventus-inter 3-0 atalanta-napoli 2-9 fiorentina-rho 4-4 .... this var grow every cicle, and i need to return in a tooltip only last 5 row. Any hint to solve this ? thank you ! m. Share this post Link to post Share on other sites
JohnOne 1,603 Posted July 16, 2011 hint? _FileCountLines() FileReadLine() AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Share this post Link to post Share on other sites
myspacee 1 Posted July 16, 2011 thank you for reply, _FileCountLines() doesn't work only for files, i store my values in a var... indirectly suggest to maintain a file to store these info ? m. Share this post Link to post Share on other sites
jchd 1,509 Posted July 16, 2011 An array seems to be a good way. Try StringSplit This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Share this post Link to post Share on other sites
Andreik 66 Posted July 16, 2011 An implementation of what jchd said: Dim $VAR Do $INPUT = InputBox("Score","Type here the score" & @CRLF & "Leave input blank to stop","") $VAR &= $INPUT & @CRLF TrayTip("Last five",DisplayLast(StringTrimRight($VAR,2),5),1) Until $INPUT = "" Func DisplayLast($VAR,$LAST=5) Local $RESULT = "" Local $SPLIT = StringSplit($VAR,@CRLF,1) If IsArray($SPLIT) Then For $INDEX = $SPLIT[0]-$LAST+1 To $SPLIT[0] If $INDEX <= 0 Then ContinueLoop $RESULT &= $SPLIT[$INDEX] & @CRLF Next EndIf Return $RESULT EndFunc When the words fail... music speaks Share this post Link to post Share on other sites
taietel 34 Posted July 16, 2011 (edited) #include <Array.au3> $sVar="juventus-inter 3-0"@LF $sVar &= "atalanta-napoli 2-9"@LF $sVar &= "fiorentina-rho 4-4"@LF $sVar &= "uytuyt-mnb 0-1"@LF $sVar &= "ytrytr-uio 1-2"@LF $sVar &= "gfdgfd-uyt 3-4" $aVar = StringSplit($sVar, @LF) _ArrayDisplay($aVar,"The whole array") $sLastFive = "" For $i=$aVar[0]-4 To $aVar[0] $sLastFive &= $aVar[$i]&@CRLF Next MsgBox(32,"Last five rows are:",$sLastFive) Edited July 16, 2011 by taietel Things you should know first...In the beginning there was only ONE! And zero...Progs:Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Share this post Link to post Share on other sites
jchd 1,509 Posted July 16, 2011 Well done guys. The best idea for the OP would probably to store successive lines in successive array entries in the first place. Since he is only interested with the 5 last lines, a fixed-sized array with 5 entries would be just good. Use something like this: Local $VAR5[5] Local $count = 0 Do $INPUT = InputBox("Score", "Type here the score" & @CRLF & "Leave input blank to stop","") If $INPUT Then $VAR5[Mod($count, 5)] = $INPUT $count += 1 EndIf Until $INPUT = "" If $count Then $count -= 1 Local $start If $count < 5 Then $start = 0 Else $start = $count - 4 EndIf For $i = $start To $count ConsoleWrite("Last line - " & $count - $i & " = " & $VAR5[Mod($i, 5)] & @LF) Next EndIf This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Share this post Link to post Share on other sites
Andreik 66 Posted July 16, 2011 ^you're a genius and gave me another idea of example using _ArrayPush() #include <Array.au3> Dim $VAR5[5] While True $INPUT = InputBox("Score", "Type here the score" & @CRLF & "Leave input blank to stop","") If $INPUT <> "" Then _ArrayPush($VAR5,$INPUT) TrayTip("Content",$VAR5[0] & @CRLF & $VAR5[1] & @CRLF & $VAR5[2] & @CRLF & $VAR5[3] & @CRLF & $VAR5[4],1) Else ExitLoop EndIf WEnd When the words fail... music speaks Share this post Link to post Share on other sites
Malkey 231 Posted July 17, 2011 The StringInStr/StringMid method in the example also works fine when there are 300,000 lines in the variable, $sVar. The StringRegExpReplace method causes the tool-tip to lag a little behind the moving cursor. expandcollapse popupHotKeySet("{ESC}", "Terminate") HotKeySet("!i", "Input") Local $sLastFive, $iLoc Global $sVar = "juventus-inter 3-0" & @LF $sVar &= "atalanta-napoli 2-9" & @CRLF $sVar &= "fiorentina-rho 4-4" & @LF ;local $sVar = FileRead("linesOut.txt") While 1 ; StringInStr/StringMid method. $iLoc = StringInStr($sVar, @LF, 0, -5 - (StringMid($sVar, StringInStr($sVar, @LF, 0, -1) + 1) = "")) $sLastFive = StringMid($sVar, $iLoc + 1) ; or ; StringRegExpReplace method. ;$sLastFive = StringRegExpReplace($sVar, "^((.*\v*)*?)((.*\v*){0,5})$", "\3") ToolTip("Press Alt+I to add line." & @CRLF & "Press Esc to exit." & @CRLF & "Last five rows are:" & @CRLF & @CRLF & StringStripWS($sLastFive, 2)) Sleep(10) WEnd Func Input() Local $INPUT While 1 $INPUT = InputBox("Score", "Type here the score" & @CRLF & "Leave input blank to stop", "") If $INPUT <> "" Then $sVar &= $INPUT & @CRLF ToolTip("Last five rows are:" & @CRLF & @CRLF & StringStripWS(StringMid($sVar, StringInStr($sVar, @LF, 0, -5 - (StringMid($sVar, StringInStr($sVar, @LF, 0, -1) + 1) = "")) + 1), 2)) Else Return EndIf Sleep(10) WEnd EndFunc ;==>Input Func Terminate() Exit 0 EndFunc ;==>Terminate Share this post Link to post Share on other sites
jchd 1,509 Posted July 17, 2011 @Andreik, Indeed, one can use _ArrayPush the way you show. But this is exactly what I wanted to avoid. look at what _ArrayPush does and imagine we are in the situation where we want to keep only the last 300 000 lines of a continuous log. _ArrayPush will move 299 999 entries around everytime it's invoked. Even worse would be ReDim to N+1 entries and _ArrayDelete the first one. Using the modulo function and working only with the indices of the array may seem a bit more convoluted at first look but reveals a much more efficient solution to the general problem, since it scales gracefully in constant time. I fully agree that with only 5 entries the question doesn't matter. I wanted to offer a more efficient way to this thread which someday could be of real value to someone else having a need for a much bigger "leftover". This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Share this post Link to post Share on other sites
dexto 4 Posted July 17, 2011 (edited) How about RegExp: ConsoleWrite(GetLastLine(FileRead(@ScriptFullPath)) & @CRLF) Func GetLastLine($txt, $lines = 1) local $got = StringRegExp($txt, '((?:.*?(?:\r\n|\n\r|\r|\n|\Z)){'&$lines&'}\Z)', 1) If Not @error Then Return $got[0] Else Return SetError(@error, 1, '') EndIf EndFunc ;==>GetLastLine Edited July 17, 2011 by dexto Share this post Link to post Share on other sites