大整数的VB6溢出错误 [英] VB6 overflow error with large integers

查看:172
本文介绍了大整数的VB6溢出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试这样设置一个整数值:

I am trying to set an integer value as such:

Dim intID as integer
intID = x * 10000

x为3或小于3时,此方法可以正常工作.但是当x为4时,这给了我错误:

This works ok when x is 3 or less. But when x is 4, this gives me the error:

运行时错误6 溢出

run-time error 6 Overflow

我不明白为什么会这样.我可以直接将intID设置为40000,没有任何问题,因此它显然能够存储大量数字.

I don't understand why this is. I can set intID to 40000 directly without any problems, so it's obviously capable of storing large numbers.

推荐答案

您*无法将vb6整数设置为40000,因为它们是带符号的16位数字,因此+32767为最大值.

You *cannot set a vb6 integer to 40000 as they are signed 16 bit numbers so +32767 is the maximum.

Long是32位类型.

不过,请注意,

Dim lngID As Long
lngID = 4 * 10000

由于文字数字默认为Integer,您仍然会溢出,以更正此错误,只需使用&键入一次,或使用CLng()强制键入一次:

You would still get an overflow as literal numbers default to Integer, to correct that just type one as long with & or cast one as long using CLng():

Dim lngID As Long
lngID = 4 * 10000&
lngID = 4 * CLng(10000)

更新:

这篇关于大整数的VB6溢出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆