Cint overflow error when value exceeds 100,000+

Tommy Skaggs picture Tommy Skaggs · Jan 23, 2012 · Viewed 41.8k times · Source

I am brand new to programming and am running into some trouble with Cint overflow error. Whenever the value reaches 100,000+ I get a Cint overflow error. This was a practice exercise in my intro to programming class. As far as I can see I coded it exactly how it was done in practice, but the practice shows using values as high as 300,000. Can someone possibly explain what I might be doing wrong?

<script language="VBscript">
Option Explicit
DIM numberofshifts, totalshift1, totalshift2, _
  totalshift3, grandtotal, shiftaverage
numberofshifts=3
totalshift1 = Inputbox("How many widgets during the first shift")
totalshift2 = Inputbox("How many widgets during the second shift")
totalshift3 = Inputbox("How many widgets during the third shift")
grandtotal = cint(totalshift1) + totalshift2 + totalshift3
shiftaverage = grandtotal / numberofshifts
Document.write "The Total of the Three Shifts is " & grandtotal
Document.write "<br>The Average of the Three Shifts is " & shiftaverage
</script>

Answer

Romeo picture Romeo · Jan 23, 2012

CInt can handle betweeen -32,768 and 32,767.

Use CLng instead of CInt.

MSDN Reference