darjab
darjab

Reputation: 129

Script error: overflow: 'CInt' - VBScript

When adding the counter next number above 5 digits: there is overflow.

Error is not if it is 5 digits.

I used VBScript:

Counter = CInt (Counter) + CInt (Qty)

I would like to use 7 digits in the numerator.

How to solve this problem?

Upvotes: 2

Views: 9844

Answers (1)

user692942
user692942

Reputation: 16682

Pretty sure this has been answered before...

Overflow Errors are probably the easiest errors to correct in VBScript. It's telling you that the current data type cannot contain the value. Because you are using CInt() to explicitly define you are working with Integer data type you have the following restriction.

From MSDN - VBScript Data Types
Integer
Contains integer in the range -32,768 to 32,767.

This doesn't give you a lot of wiggle room, so instead use Long or Double (if working with floating point numbers or it's just too big for Long)

From MSDN - VBScript Data Types
Long
Contains integer in the range -2,147,483,648 to 2,147,483,647.

Double
Contains a double-precision, floating-point number in the range -1.79769313486232E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values.

the equivalent function for converting to Long is Clng() and for Double is CDbl().


Useful Links

Upvotes: 5

Related Questions