JohnRichard Posted April 7, 2011 Share Posted April 7, 2011 hello guys. i need advise/help on your expertise. i'm kinda stuck on my script. i have this text log on which each records will append after the last line as seen on my sample text file. i wanted that the last entry up to the first entry on the text file will be displayed as first up to the records. i started with my script but is displays from the first entry down to the last entry. i wanted it the other way. i have this script but i'm stuck... this first script works fine. it displays from first to the last entry from the log file... #include <file.au3> Dim $aRecords If Not _FileReadToArray(@DesktopDir & "\log.txt",$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf $CountLines = _FileCountLines(@DesktopDir & "\log.txt") MsgBox(64, "Error log recordcount", "There are " & $CountLines & " in the error.log.") For $x = 1 to $aRecords[0] Msgbox(0,'Record:' & $x, $aRecords[$x]) Next I've stuck on this script and will display only the last entry from the text file. #include <file.au3> Dim $aRecords If Not _FileReadToArray(@DesktopDir & "\log.txt",$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf $CountLines = _FileCountLines(@DesktopDir & "\log.txt") MsgBox(64, "Error log recordcount", "There are " & $CountLines & " in the error.log.") For $x = $CountLines to $aRecords[0] Msgbox(0,'Record:' & $x, $aRecords[$x]) Nextlog.txt Link to comment Share on other sites More sharing options...
smartee Posted April 7, 2011 Share Posted April 7, 2011 #include <file.au3> Dim $aRecords If Not _FileReadToArray(@DesktopDir & "\log.txt",$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf $CountLines = _FileCountLines(@DesktopDir & "\log.txt") MsgBox(64, "Error log recordcount", "There are " & $CountLines & " in the error.log.") For $x = $aRecords[0] to 1 Step -1 Msgbox(0,'Record:' & $x, $aRecords[$x]) Next Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 7, 2011 Moderators Share Posted April 7, 2011 JohnRichard, display only the last entry from the text fileWhich is exactly what this line: For $x = $CountLines to $aRecords[0] is telling AutoIt to do! $Countlines is the number of lines - as is $aRecords[0]. So the loop runs just the once and you get only the final line. If you were to use: For $x = $aRecords[0] To 1 Step -1 you would read in the file lines in reverse order - which is what you want. Incidentally, why use _FileCountLines? You already have the answer automatically in $aRecords[0]. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
JohnRichard Posted April 7, 2011 Author Share Posted April 7, 2011 #include <file.au3> Dim $aRecords If Not _FileReadToArray(@DesktopDir & "\log.txt",$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf $CountLines = _FileCountLines(@DesktopDir & "\log.txt") MsgBox(64, "Error log recordcount", "There are " & $CountLines & " in the error.log.") For $x = $aRecords[0] to 1 Step -1 Msgbox(0,'Record:' & $x, $aRecords[$x]) Next hi smartee. it works great. i have not think of using this Step command. thanks Link to comment Share on other sites More sharing options...
JohnRichard Posted April 7, 2011 Author Share Posted April 7, 2011 JohnRichard, Which is exactly what this line: For $x = $CountLines to $aRecords[0] is telling AutoIt to do! $Countlines is the number of lines - as is $aRecords[0]. So the loop runs just the once and you get only the final line. If you were to use: For $x = $aRecords[0] To 1 Step -1 you would read in the file lines in reverse order - which is what you want. Incidentally, why use _FileCountLines? You already have the answer automatically in $aRecords[0]. M23 hi melba...i've just use _FileCountLines just for my testing. sorry i forgot to remove that lines... actually i've played around this script... For $x = $aRecords[0] To 1 Step -1 but i have not think of using the command Step -1. thanks for a great explanation....this is additional knowledge for me using the AutoIT. 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