ASP Classic overflow

I was wondering if anyone could help me, as I was blinded to what, in my opinion, is a simple cause of a simple mistake.

I have this code:

 doRound1(x1)
  denom1 = 5
  y1 = denom1 - x1 mod denom1
  if y1 <> denom1 then
    x1= x1+y1
  end if

  doRound1=x1
 End function

 'theCalc = 20488888888.684
  theCalc = cDbl(11111111111) * 1.844
  doRound1(theCalc)

I get this error

Microsoft VBScript runtime  error '800a0006'
Overflow: 'x1'

Called by this line in the above code:

 y1 = denom1 - x1 mod denom1

Any ideas? As I said, I have come to a standstill.

+5
source share
2 answers

The answer looks like PRB: Overflow with Integer Division and MOD Operator :

Visual Basic Mod operator() , , . , , (2 147 483 647) , (-2,147,483,648), .

:

, , , :

Dim dblX as Double
Dim dblY as Double
dblX = 2147483648                ' numerator
dblY = 123                       ' denominator

' round off the numerator and denominator (ensure number is .0)
dblX = INT(dblX + .5)         
dblY = INT(dblY + .5)      

' Emulate integer division
MsgBox FIX(dblX / dblY)             
' Emulate modulo arithmetic
MsgBox dblX - ( dblY * FIX(dblX / dblY) )
+4

, , , ASP Classic int ( 32767).

 Function doRound1(x1)
  x1 = CDbl(x1)
  denom1 = CDbl(5)
  y1 = denom1 - x1 mod denom1
  if y1 <> denom1 then
    x1= x1+y1
  end if

  doRound1=x1
 End function

. .

+1

All Articles