readmedottxt Posted April 27, 2010 Posted April 27, 2010 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
readmedottxt Posted April 27, 2010 Author Posted April 27, 2010 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
omikron48 Posted April 27, 2010 Posted April 27, 2010 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
readmedottxt Posted April 27, 2010 Author Posted April 27, 2010 (edited) 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 April 27, 2010 by readmedottxt
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now