0

How do you do Modulo in Brightscript?



I can't find it in the docs. It's not the % operator.

3 comments

  • Avatar
    Lee Dydo Official comment

    This has changed since 2010.
    You modulo by writing MOD between two numbers, eg:

    remainder = 20 MOD 19

  • 0
    Avatar
    RokuLyndon


    There isn't a modulo function so you would need to calculate it manually using a script.
  • 0
    Avatar
    Bright Scripters

    Never done that, but this might work in brightscript

     

    function Modulo(a as integer, b as integer) as integer

    if b = 0 then

       print "cannot divide by 0"

       stop

    else if b = 1 then

       return 0

    else if a >= b then

       return a - cint(a/b) * b

    else if a < b

       return a

    end if

    end function

     

     

     

Please sign in to leave a comment.