# Mod question

Okay so I read the goods on “mod” and he is my code

Dim d As Double
Dim i, x, np As Integer

…other code

If x < 22 then
d = (canvisWP / pjWidth)
np = CType(d, Integer)
i = canvisWP mod pjWidth
if i >0 then
numProjectors = (np +1)
end if

``````txtNumberOfProjectors.text = str(numProjectors)
``````

else
// add error handle for too many PJs
end

When I run the app and input number (canvisWP (Integer) is 11667) and (pjWidth (Integer) is 1920) I assume mod would result with “1” but I get 467, what gives?

I get 147 with those values, and it’s correct. Why do you think it would be 1? And if it’s 467, the values aren’t what you think they are.

[code] Dim c as integer
Dim p as integer
Dim i as integer

c=11667
p=1920
i=c mod p
msgbox format(i,"#")[/code]

Gives 147.

Hi Jim!

mod is the ‘remainder’ after (integer) division.
for example:
13 mod 5 is 3
13/5 = 2r3
or 2 x 5’s with 3 left over

your mod calculation should have 147 pixels left over
you’ll need 1 more projector whether you have 1 or 1919 pixels left over.

But if you get 467 you have other logic errors.

Ok two things, first my second number in the above example was supposed to be 1400 not 1920, 1920 is etched in my brain. Second, I was totally misunderstanding result of Mod, but I get it now after a nights sleep. I was doing the math on a calculators 11667/1400= 8.3335… So I was seeing the remainder as .3335 and since it was being place in an integer, I was thinking it would be rounded to 1. I forgot to take into account what the .3335 really represented.

John,
Great to hear from you (yes I stay invisible these days). And yes, the extra projectors is what I am testing for (on a blend). The routine works since ‘i’ is greater then 0 in my example.

Thank folks for the help.
JMW