I get an overflow using the MOD function for the following data.

Posted by Bruce on Thu 25 Jan 2007 01:55 PM — 2 posts, 14,058 views.

#0
I get an overflow for the following VBScript code, and do not know what data type to cast to, so I do not get the "overflow" except. Any idea on this is greatly appreciated.

dim iFileSize
dim Remainder

iFileSize = 2206678860
Remainder= CDbl(iFileSize) Mod (228)

What should I cast my iFileSize to, to avoid an overflow?
If possible, please contact me directly at byang@cmsdirect.com

Thank you.
USA #1
You might want to read:
http://blogs.msdn.com/ericlippert/archive/2004/12/01/273222.aspx
(Incidentally, #5 in the result list for google "vbscript mod function")

In particular:
Quote:
And indeed, the writer is correct. 2147483647 mod 2 returns 1, but 2147483648 mod 2 produces a type mismatch error. Since that's 2^31, you should be able to guess at what's going on here -- the mod operator only operates on values that can be fit into a 32 bit signed integer.


The page also suggests a solution, in the form of a custom-written mod function.

(By the way -- normally we strongly encourage public replies so that everybody can see the solution to the problem. Private replies defeat the purpose of a public help forum.)