Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

how to count how many loops was performed?



  • Please log in to reply
5 replies to this topic
farfaraway
  • Members
  • 89 posts
  • Last active: Sep 18 2015 04:52 PM
  • Joined: 13 Nov 2013
Loop, read, %A_ScriptDir%\FileNo.txt
{
    n2 := A_Index
	Loop, parse, A_LoopReadLine, %A_Tab%
    {
        FileNo%n2% := A_LoopField
		sleep 50
    }
}

Now I need to apply these saved variable elsewhere.  How can I tell how many loops was performed?

 

i can only think of having an input box to enter in how many numbers was in the text file. However these numbers varies daily so i can't have an exact number every time. 

 



lkb3
  • Members
  • 7 posts
  • Last active: Mar 21 2014 05:55 PM
  • Joined: 07 Mar 2014

I'm not sure which loop you're wanting to count, but if you just want to count iterations of the outer loop, I think this will do what you want.

counter:=0
    Loop, read, %A_ScriptDir%\FileNo.txt
    {
        n2 := A_Index
    	Loop, parse, A_LoopReadLine, %A_Tab%
        {
            FileNo%n2% := A_LoopField
    		sleep 50
        }
        counter:= counter +1
}


RHCP
  • Members
  • 1228 posts
  • Last active: Apr 08 2017 06:17 PM
  • Joined: 29 May 2006
✓  Best Answer
count := 0
Loop, read, %A_ScriptDir%\FileNo.txt
{
    n2 := A_Index
    Loop, parse, A_LoopReadLine, %A_Tab%
    {
        count++
        FileNo%n2% := A_LoopField
        sleep 50
    }
}
msgbox There are %count% FileNoX variabls 

I assume you just want to count the total number of times the internal "loop, parse" runs. You already have the external loop count in variable "n2".

 

Personally, I would use a real array rather than a pseudo array to store the data. When using an array with array.insert(Value), you can easily check the array size using array.MaxIndex()



farfaraway
  • Members
  • 89 posts
  • Last active: Sep 18 2015 04:52 PM
  • Joined: 13 Nov 2013

maybe something like retrieving the max count of the loop performed and then saving that number into a variable?



farfaraway
  • Members
  • 89 posts
  • Last active: Sep 18 2015 04:52 PM
  • Joined: 13 Nov 2013

thanks for the quick replies guys! i'll check out the codes and report back.



farfaraway
  • Members
  • 89 posts
  • Last active: Sep 18 2015 04:52 PM
  • Joined: 13 Nov 2013

Both works and it's exactly what i needed it to do.  I still have a lot to learn and getting into arrays is definitely next.  Thanks for the quick tips guys!