2

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?

darjab
  • 129
  • 1
  • 8
  • 2
    If your *Counter* isn't a floating-point number, you should use [`CLng()`](https://msdn.microsoft.com/en-us/library/ck4c5842%28v=vs.84%29.aspx?f=255&MSPPError=-2147217396) – 41686d6564 stands w. Palestine Jul 13 '16 at 10:35
  • @GeniuSBraiN while I agree it depends how big your numbers are going to be. OP mentions 7 digits so `Long` should be sufficient. – user692942 Jul 13 '16 at 11:00

1 Answers1

5

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

Community
  • 1
  • 1
user692942
  • 16,398
  • 7
  • 76
  • 175
  • 1
    The OP didn't mention that he's working with floating-point numbers, so probably `Long` should be used instead of `Double` – 41686d6564 stands w. Palestine Jul 13 '16 at 10:37
  • @GeniuSBraiN Absolutely right, I didn't read the code just saw it was a Overflow Error on an Integer. If they are using variables like `Counter` doubt it will be floating point. There are occasions though when even `Long` isn't enough. – user692942 Jul 13 '16 at 10:41