Jump to content

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


Recommended Posts

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
Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

  • Moderators

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...