# 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```
##### 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```

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

##### 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```
Ha! Thanks, I thought it would be much trickier to solve.
##### Share on other sites

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

##### Share on other sites

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

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

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...