Jump to content

for to next


Recommended Posts

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

Oh come on now, @ScriptDir & "\test.txt" is not a number :(

Edit: Nor an array, what are you thinking with?

Edited by AdmiralAlkex
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

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 by redLabel
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

  • Moderators

redLable,

i just didn't understand how your script was working

Then 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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...