Sign in to follow this  
Followers 0
JohnRichard

Need help to display properly

5 posts in this topic

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])
Next

log.txt

Share this post


Link to post
Share on other sites



#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

Share this post


Link to post
Share on other sites

JohnRichard,

display only the last entry from the text file

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]. :P

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#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

Share this post


Link to post
Share on other sites

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]. :P

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.

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  
Followers 0