Bill....come to my rescue

# Thread: Bill....come to my rescue

1. Senior Member
Join Date
Dec 1969
Posts
336

## Bill....come to my rescue

I&#039;m using this calendar formula and it&#039;s not always returning the proper sum for me. I can&#039;t figure out where it&#039;s going wrong. Here it is.<BR><BR>varOne = 5<BR>varTwo = 31<BR><BR>varSum = 6 - (int((42 - (varOne + varTwo)) / 7))<BR>here&#039;s my logic, so let me know if my logic is screwed up<BR><BR>varSum = 6 - (int((42 - (5 + 31)) / 7))<BR>varSum = 6 - (int((42 - (36)) / 7))<BR>varSum = 6 - (int((6)) / 7))<BR>varSum = 6 - (int(0.871))<BR>varSum = 6 - (1)<BR>varSum = 5<BR><BR>However, when I run the code, it&#039;s returning 6. Bill, can you explain this to me? Thanks.

2. Senior Member
Join Date
Dec 1969
Posts
2,493

## RE: Bill....come to my rescue

Here is what I did, Change you int&#039;s to Cint because int gives you a 0 because you can&#039;t divide 6 by 7 and get a positive value so Cint rounds it up<BR><BR>The end result is a 5<BR><BR>varOne = 5 <BR>varTwo = 31<BR><BR>varSum = 6 - (Cint((42 - (varOne + varTwo)) / 7)) <BR><BR>Response.write "VarOne = " & VarOne & "&lt;br&gt;"<BR>Response.write "VarTwo = " & VarTwo & "&lt;br&gt;"<BR>Response.write "varOne + varTwo = " & varOne + varTwo & "&lt;br&gt;"<BR>Response.write "42 - (varOne + varTwo) = " & CInt(42 - (varOne + varTwo)) & "&lt;br&gt;"<BR>Response.write "Cint((42 - (varOne + varTwo)) / 7) = " & Cint((42 - (varOne + varTwo)) / 7) & "&lt;br&gt;"<BR>response.write "6 - (Cint((42 - (varOne + varTwo)) / 7)) = " & 6 - (Cint((42 - (varOne + varTwo)) / 7)) & "&lt;br&gt;"<BR>response.write "varSum = " & varSum

3. Senior Member
Join Date
Dec 1969
Posts
336

## not completely working

That works fine when the result should be 4 or 5, but when it should be 6, I&#039;m still getting a 5. Any ideas why that might be happening?

4. Senior Member
Join Date
Dec 1969
Posts
96,118