View Full Version : Mod or Modulus function?
ScottInTexas
05-23-2003, 12:39 PM
I cannot find a Modulus function in vbScript. Is there one? If not, is there a way to accomplish the same thing?
brothercake
05-23-2003, 01:01 PM
if a/b creates a float then all you need to find the modulo is the trailing float multiplied by b.
eg: a = 10 and b = 4; a/b = 2.5; a%b is the same as 0.5*b. If the float is a recurring number, just round the result to the nearest integer.
I don't know any VB though - I'd assume that there is such a function built in.
Roelf
05-23-2003, 01:43 PM
its not a function, but an operator:
http://www.devguru.com/Technologies/vbscript/quickref/mod.html
i use it like this
if 5 Mod 2 = 0 then
etc
so if you only need the value, use
variable = a Mod b
<edit>posts crossed </edit>
ScottInTexas
05-23-2003, 06:42 PM
Thanks RAF,
I have used it in other programming languages, just couldn't find the reference in VBScript.
whammy
05-24-2003, 12:38 AM
http://www.sloppycode.net/vbscript/?m=2609
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.