我是编程的新手,并且遇到了Cint溢出错误的麻烦.每当值达到100,000+时,我都会收到Cint溢出错误.这是我编程课程的一个练习练习.据我所知,我在实践中完全按照它编写的方式对其进行了编码,但实践表明使用的值高达300,000.有人可能会解释我可能做错了什么吗?
<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>
Run Code Online (Sandbox Code Playgroud) 由于数值超过了VBScript INT可以存储的值,我收到了一个非常讨厌的错误消息(实际上是用户)...这完全是twitpocalypse的情况.
由于CINT()在这种情况下不起作用,最好的解决方法是什么?
requestqty = 40200
CInt() max = 32767
CInt(requestqty)
Run Code Online (Sandbox Code Playgroud)
编辑
CLng()似乎可以解决问题,将代码更改为所有CInt()到CLng()的任何风险.从我在下面阅读的内容和其他网站上看,似乎甚至没有理由使用CInt().我没有写这个特定的应用程序,也不知道为什么一个被用于另一个,但更愿意不对这个问题进行限制并在应用程序中完全解决这个问题,所以它不会再发生......