VB6 大整数溢出错误

标签 vb6 integer overflow

我正在尝试设置一个整数值,如下所示:

Dim intID as integer
intID = x * 10000

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

run-time error 6 Overflow

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

enter image description here

最佳答案

不能将 vb6 整数设置为 40000,因为它们是带符号的 16 位数字,因此 +32767 是最大值。

Long 是 32 位类型。

但是请注意,如果您要:

Dim lngID As Long
lngID = 4 * 10000

您仍然会遇到溢出,因为文字数字默认为 Integer,要更正该问题,只需使用 & 键入 1 as long 或使用 CLng() 强制转换 1 as long:

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

更新:

enter image description here

关于VB6 大整数溢出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5895816/

相关文章:

linux - 通过 GDB 运行程序时函数位置是否改变?

excel - 如何在 vb6 中关闭所有事件的 .xls 文件

c++ - 输入流的 std::setfill 和 std::setw ?

css - 更改 HTML 溢出

java - "If the number is contained in the text and is repeated, return the sum of the number for each time it is repeated. Otherwise return 0."

c++ - 两个字符相加产生 int

需要 CSS 溢出帮助 - 对于 jquery 崩溃

.net - 如何在 VB6 中使用 .NET .DLL 文件或库?

excel - 使用 Microsoft.Jet.OLEDB 提供程序时是否需要 MS Office?

winapi - 如何使用 Vb6 中的 SHGetKnownFolderPath 函数