AutoHotkey Community

It is currently May 27th, 2012, 12:45 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: December 21st, 2009, 12:41 am 
Offline

Joined: August 22nd, 2009, 11:23 pm
Posts: 294
My Brain is fried trying to get this Loop to work.

The goal is read each line of the text file and find each line
that matches the SearchText using the TF_Find function

Then loading the Text file and reading each line,
cheicking for a match, it loops until
a match is found, it then parses the "FoundRows" values and
displays the Row number & Script title.

Then it should continue to read the next line/s in the text file
following the 1st match until it finds the next match,
then gets the next value of "FoundRows" and repeats this until all the matches are found.

Ther problem is the "Loop, parse, FoundRows, `, "
is not exiting after finding the "SearchText" match and
going to the "Loop, parse, A_LoopReadLine, `n`r " and
incrementing to the next line in the text file.

Instead it stays in the "FoundRows" loop & displays
All the lines containing the SearchText matches x times for each
FoundRow value found, then each Ttitle found.

This is part of a much larger script. Please DO NOT change the script
or it can impact other areas of the larger script.
other than to FIX the line/s when it's stuck in the Loop rather than
incrementing to the next line in the Text File & the next Row & Title
in the "FoundRows" loop.

Thanks for any help you can provide.

Have a Great Holiday and New Year. :lol:

Code:

; this text file only needs to be created once.
; It is a smalll sample of a significantly larger text file.

TFList =
(
Add Entry to List                                                   
Add File                                                                                                                                                   
AHK Running Scripts Restarter                                                                                       
API Lists + Code                                                                                                                                           
Array MultiArray from MultiFiles                       
Array Pass to Function                                                                                             
Array Read Write                                                                                                                                                   
Array to INI                                                                                                     
Auto-Insert Text with Tags in any Script                                       
AutoComplete                                               
AutoLookupDDL                                               
Button Focus Send Click                                                                                                               
CheckBox Run Programs                                                                                           
Checkbox Tabbed Tools                                                                                           
Class Get Control Class Function                                 
Close All Group                                                                                                                                                   
Close All Windows                                                                                                                                                   
Close All Windows                                                                                                                                                   
Code Add Here                                                                                                                                                   
Color Set Color Background Transparent                                                                         
ColorPicker Magnifier                                                                         
ComboBox Fill Get Item                                                                                                                                                   
)

FileAppend, %TFList%, %A_ScriptDir%\FoundTitles.txt

SearchText = Color
F = %A_ScriptDir%\ScripletLibTitles.txt
FoundRows := TF_Find(F, 1,0, SearchText, 0, 0) ; Find all line numbers with the SearchText.
MsgBox % TF_Find(F, 1, 0, SearchText, 0, 0)  ; result:  - 0, 0 returns all results by line number

Loop, read, %F%
{
    Loop, parse, A_LoopReadLine, `n`r
    {
        IfinString, A_LoopReadLine, %SearchText%
        {
            Loop, parse, FoundRows, `,
            {
                MsgBox, , FoundRows,  %A_LoopField% is %A_LoopReadLine%   
            }   
        }   
            Else If A_LoopReadLine <> SearchText
            Msgbox %A_LoopReadLine% <> %SearchText%
        }
}

Return

ESC::ExitApp

#Include %A_ScriptDir%\TF.ahk  ; version 3.1 
; http://www.autohotkey.com/forum/topic46195.html   TF.ahk Download

_________________
Image
"Man's quest for knowledge is an expanding series whose limit is infinity"


Last edited by txquestor on December 21st, 2009, 6:21 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 21st, 2009, 8:33 am 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Try to change the Loop, parse line
Code:
Loop, parse, A_LoopReadLine, `n, `r
. I believe `n`r is incorrect and should be `r`n to start with, but I always parse on `n and explicitly add `r as omitchar. Haven't looked at the rest of the script.

Edit: I also prefer to use () with If expressions, seems to work much better

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 21st, 2009, 5:44 pm 
Offline

Joined: August 22nd, 2009, 11:23 pm
Posts: 294
Thanks Hugov, :lol:
However, it didn't make any difference in correcting the loop problem.

More specifically, the "Loop, parse, FoundRows, `, " does the following

It finds four (4)instances of the SearchText = color
Rows: 20, 21, 41, 42

1. 1st loop displays Row & Title for; Row 1, Title 1
and increments through Row 19, Title 19
then matches on ...

Doesn't increment Title
1. 1st loop displays Row & Title for; row 20, Title 20
2. 2nd loop displays Row & Title for; row 21, Title 20
Row 22 <> color
---
---
Row 40 <> color
3. 3rd loop displays Row & Title for; row 41, Title 20
4. 4th loop displays Row & Title for; row 42, Title 20
Row 43 <> color

Then increments Title to 21 after display pattern above
Then 22 Title 21
Then 23 Title 41
Then 24 Title 42

Should show:

1st loop displays Row & Title for; Row 1, Title 1
and increments through Row 19, Title 19
then yhe "Loop, parse, FoundRows, `, "
matches on ...

1. Row 20, Title 20
2. Row 21, Title 21
Row 22 <> color
---
---
Row 40 <> color
3. Row 41, Title 41
4. Row 42, Title 42

I've tried many combinations of Loops, but I'm just not seeing it.
Either a Fried Brain or Brain Fart.

Thanks agiain for any help you or anyone can provide

_________________
Image
"Man's quest for knowledge is an expanding series whose limit is infinity"


Last edited by txquestor on December 21st, 2009, 7:17 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 21st, 2009, 5:51 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
I dunno what you want to do, you use TF_Find to find the lines, they you are going to parse the file again to do what? Find the lines? You already have them with TF_Find so what is the point of parsing it a second time? If you ask me you don't need the loops at all by the looks of it

Edit: you have nested the wrong loops, or at least one to many, you don't need to parse a_loopreadline with `r`n as it is already a line. Read up on the various loop types before you continue with your script.
Code:
Loop, parse, %F%, `n, `r
{
        IfInString, A_LoopReadLine, %SearchText%
        {
            Loop, parse, FoundRows, `,
            {
                MsgBox, , FoundRows,  "1: " %A_LoopField% is %A_LoopReadLine%   
            }   
        }   
            Else If (A_LoopReadLine <> SearchText)
            Msgbox "2: " %A_LoopReadLine% <> %SearchText%
}

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 21st, 2009, 7:20 pm 
Offline

Joined: August 22nd, 2009, 11:23 pm
Posts: 294
Hugo, thanks. :lol:

I'll just start all over again with what I really want to accomplish.
I guess I just got lost in my loops and forgot what goal I wanted to achieve. :roll: :oops:

_________________
Image
"Man's quest for knowledge is an expanding series whose limit is infinity"


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot], iDrug, Leef_me, Ohnitiel, XstatyK and 17 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group