Necromorph Posted April 9, 2010 Share Posted April 9, 2010 i don't really understand how to use this yet, im trying to figure it out. i want to read every 6th line of a text doc till i reach the end, which could be any given length. how do i do this $log = @ScriptDir & "\test.txt" For $x = 1 to $log[0] Step 6 FileReadLine($log, $x) Next i just don't get it, im sure this is way off. thanks for the help. Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted April 9, 2010 Share Posted April 9, 2010 (edited) Oh come on now, @ScriptDir & "\test.txt" is not a number Edit: Nor an array, what are you thinking with? Edited April 9, 2010 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
BugFix Posted April 9, 2010 Share Posted April 9, 2010 (edited) You must check Ubound: Use _FileCountLines. For $x = 1 to $log[0] Step 6 FileReadLine($log, $x) If $x + 6 > $log[0] Then ExitLoop Next Edited April 9, 2010 by BugFix Best Regards BugFix Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 9, 2010 Moderators Share Posted April 9, 2010 redLabel,I would do it this way:$hFile = FileOpen(@ScriptDir & "\Test.txt") $iCount = 1 While 1 $sText = FileReadLine($hFile) If @error Then ExitLoop If Mod($iCount, 6) = 0 Then ConsoleWrite($sText & @CRLF) $iCount += 1 WEnd FileClose($hFile)Why? Because if you give a line number to FileReadLine, it reads through the whole file each time to get up to that line. Can you imagine how long that would take if the file is a biggie? Much better to let AutoIt read through the file a line at a time - which it does automatically - and then just extract every 6th line like the code above! I hope the explanation is clear - ask again if not. 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...
Necromorph Posted April 9, 2010 Author Share Posted April 9, 2010 @melba23 thank you very much for your help, works perfect!! Link to comment Share on other sites More sharing options...
Necromorph Posted April 9, 2010 Author Share Posted April 9, 2010 (edited) actually i have a little more to this i need help on. here is a n example text file i am reading from <Start> totaltime: 0.5 hours date: 2010/04/05 starttime: 04:00 PM endtime: 04:30 PM company: user: tasks completed: Quickbooks file locked for editing issue totaltime: 1 hours date: 2010/04/05 starttime: 04:30 PM endtime: 05:00 PM company: user: none tasks completed: Work on server rack drawing. totaltime: 1.5 hours date: 2010/04/05 starttime: 05:00 PM endtime: 06:00 PM company: user: none tasks completed: Work on server2, RAID crashed. <End> here is my script (thanks again) $hFile = FileOpen(@ScriptDir & "\Testlog.txt") $iCount = 5 While 1 $xLeft = StringTrimLeft(FileReadLine($hFile), 11) $xRight = StringTrimRight($xLeft, 18) $xHours = Number($xLeft) If Mod($iCount, 6) = 0 Then MsgBox(0, "", $xHours & @CRLF) $iCount += 1 WEnd FileClose($hFile) basiacally i want to add all the "total hours" up. can i list it to an array and do it? thanks again!! Edited April 9, 2010 by redLabel Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 9, 2010 Moderators Share Posted April 9, 2010 redLabel,I should start charging....... Try this:#Include <String.au3> $hFile = FileOpen(@ScriptDir & "\Test.txt") $iCount = 1 $nHours = 0 While 1 $sText = FileReadLine($hFile) If @error Then ExitLoop If Mod($iCount, 6) = 1 Then ; Adjust this value to match the 1-based line of the first "totaltime" line $aHours = _StringBetween($sText, "totaltime: ", "hours") $nHours += Number($aHours[0]) EndIf $iCount += 1 WEnd FileClose($hFile) MsgBox(0, "Total", $nHours, 1)You will need to adjust the figure in the Mod line as explained. 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...
Necromorph Posted April 9, 2010 Author Share Posted April 9, 2010 thanks again, but i get an error in regaurds to the $nHours += Number($aHours[0]) it says that 'Subscript used with non-array Variable;==> not sure what that means exactly. thanks again. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 9, 2010 Moderators Share Posted April 9, 2010 redLabel,I did tell you that you might need to adjust the Mod check value: #Include <String.au3> $hFile = FileOpen(@ScriptDir & "\Test.txt") $iCount = 1 $nHours = 0 While 1 $sText = FileReadLine($hFile) If @error Then ExitLoop If Mod($iCount, 6) = 1 Then ; Adjust the "1" in the line above until you get the "totaltime" lines appearing in the SciTE console ; Then remove this ConsoleWrite line ConsoleWrite($sText & @CRLF) ; And uncomment these 2 lines ;$aHours = _StringBetween($sText, "totaltime: ", "hours") ;$nHours += Number($aHours[0]) EndIf $iCount += 1 WEnd FileClose($hFile) MsgBox(0, "Total", $nHours, 1)You have to do some work yourself, you know! 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...
Necromorph Posted April 10, 2010 Author Share Posted April 10, 2010 sorry, about all this, i just didn't understand how your script was working, and i also didn't know that you can output with the "consolewrite" function like that, but now i understand what is happening. thank you again. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 10, 2010 Moderators Share Posted April 10, 2010 redLable,i just didn't understand how your script was workingThen do please ask for an explanation. Just plugging a chunk of code into your script without understanding what is going on can only lead to trouble in the long-term.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...
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