Sign in to follow this  
Followers 0
blb078

Loop w/counter help.

6 posts in this topic

I'm trying to have some code loop w/a counter and to keep running after it does the function once the count has met but start back over. What I have currenty is.

While $counter < 3

   some
   code
   here

$counter = $counter +1

WEnd

FunctionAfterCountMet()

When I run it, it kind of works only that it doesn't start back over at the top after the count is met and it does the function, it just stops after that.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You want an infinite loop that calls a function when a value is met and then starts over again? Something like this? Make sure that you add some code to end the script!

$counter = 0
$limit = 3
While 1
    some
    code
    here
    If $counter = $limit Then
        FunctionAfterCountMet()
        $counter = 0
    Else
        $counter += 1
    EndIf
WEnd

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I see you don't have the counter incrementing by 1 each time, so what is keeping track of that? Wont the counter always be 0?

Share this post


Link to post
Share on other sites

I see you don't have the counter incrementing by 1 each time, so what is keeping track of that? Wont the counter always be 0?

I guess it is part of "some code here".

I would have used a For-loop. It does the counting for you.

While 1
    For $iX = 1 To 3
        some
        code
        here
    Next
    FunctionAfterCountMet()
WEnd

Share this post


Link to post
Share on other sites

Thx a lot both of you, got it all working.

Share this post


Link to post
Share on other sites

I see you don't have the counter incrementing by 1 each time, so what is keeping track of that? Wont the counter always be 0?

Oops, missed that. I updated my code above.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0