Jump to content

Obtaining a multiple using a counter


Recommended Posts

Here's my predicament - I have a script that uses a counter in a loop, eg:

$i = $i + 1

I need a trigger once every three, five and seven numbers. Is there a function to do this or would i need to divide $i by the trigger and work out if its a whole number?

Thanks

Link to comment
Share on other sites

Here's my predicament - I have a script that uses a counter in a loop, eg:

$i = $i + 1

I need a trigger once every three, five and seven numbers. Is there a function to do this or would i need to divide $i by the trigger and work out if its a whole number?

Thanks

This does work, but is it the best way to do it?

$RetVal = $i / 5
if Round($RetVal) = $RetVal Then
    GUICtrlSetData($Report, "Increment: " & $i)
EndIf
Link to comment
Share on other sites

Try using the modulo (remainder).

For $i = 1 To 10
    If Mod($i, 3) == 0 Then
        MsgBox(0x2000, "3rd Number", $i)
    ElseIf Mod($i, 5) == 0 Then
        MsgBox(0x2000, "5th Number", $i)
    ElseIf Mod($i, 7) == 0 Then
        MsgBox(0x2000, "7th Number", $i)
    EndIf
Next

I hadn't used modulo since leaving school!

Thank you - it's applied a solution in a very intelligent way.

Edited by readmedottxt
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...