Jump to content
Sign in to follow this  
litlmike

If Divisible by 5, then Func (). Or Every fifth time.

Recommended Posts

litlmike

How can I call this only when the counter is divisble by 5?

Example:

Lets say that I have this function, but I only want it to call Func Msg_Box every 5th time.

$i = 0
While $i < 100
    Func Msg_Box ()
    $i +=1
WEnd

Func Msg_Box ()
    MsgBox(4096, "Test", "This box will time out in 1 second", 1)
    Sleep (2000)
EndFunc

Share this post


Link to post
Share on other sites
GaryFrost

For $i = 0 To 99
 If Not Mod($i,5) Then Msg_Box ()
Next
 
Func Msg_Box ()
    MsgBox(4096, "Test: " & $i, "This box will time out in 1 second", 1)
    Sleep (2000)
EndFunc


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites
BPBNA

Whats wrong with Mod? It works fine. You could always do the division yourself and check for a decimal.

Share this post


Link to post
Share on other sites
SmOke_N

Actually, to play Devil's Advocate, is there a way to do this without using Mod()?

For $i = 0 To 99
 If IsInt($i / 5) Then Msg_Box ()
Next
 
Func Msg_Box ()
    MsgBox(4096, "Test: " & $i, "This box will time out in 1 second")
    Sleep(2000)
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.