AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Compliicated Loop Fries Brain

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
txquestor



Joined: 22 Aug 2009
Posts: 294

PostPosted: Sun Dec 20, 2009 11:41 pm    Post subject: Compliicated Loop Fries Brain Reply with quote

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. Laughing

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

_________________

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


Last edited by txquestor on Mon Dec 21, 2009 5:21 pm; edited 2 times in total
Back to top
View user's profile Send private message
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Mon Dec 21, 2009 7:33 am    Post subject: Reply with quote

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 Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
txquestor



Joined: 22 Aug 2009
Posts: 294

PostPosted: Mon Dec 21, 2009 4:44 pm    Post subject: Reply with quote

Thanks Hugov, Laughing
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
_________________

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


Last edited by txquestor on Mon Dec 21, 2009 6:17 pm; edited 1 time in total
Back to top
View user's profile Send private message
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Mon Dec 21, 2009 4:51 pm    Post subject: Reply with quote

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 Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
txquestor



Joined: 22 Aug 2009
Posts: 294

PostPosted: Mon Dec 21, 2009 6:20 pm    Post subject: Reply with quote

Hugo, thanks. Laughing

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. Rolling Eyes Embarassed
_________________

"Man's quest for knowledge is an expanding series whose limit is infinity"
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group