我在 Visual Basic 2010 中收到错误 "Overflow."

I am getting the error "Overflow." in Visual Basic 2010

Dim clicks As Integer
clicks = 0

If clicks >= 10000000000000000000 Then
    a19.ForeColor = Color.FromArgb(0, 153, 0)
End If

10000000000000000000 及以上给出错误。 有什么办法可以无限长的数字吗?

您可以使用 Long 而不是 Integer 来达到大约 9 * 10E18(9 后跟 18 个零)。如果 Long

,则在文字上使用 L 后缀
Dim bigNumber as Long = 5000000000000000000L

如果您想要任何大小的整数,请查看 BigInteger Structure。例如(以下需要引用 System.Numerics DLL 以及语句 Imports System.Numerics

    Dim clicks As BigInteger = 0

    'Code that updates click goes here

    Dim limit As BigInteger = BigInteger.Parse("10000000000000000000")
    If clicks >= limit Then
        a19.ForeColor = Color.FromArgb(0, 153, 0)
    End If

您也可以使用 Double 来保存大到 1E308 的数字,但它不能保存 308 位十进制数字,因此数字只能是近似值。

在计算机科学中,数字最常表示为 integer。整数通常定义为 32 位有符号 整数,这意味着该值最多只能容纳从 -(2^31) 到 (2^31)- 的值1.要使用更大的数字,您可能需要检查其他整数类型。最常用的大整数是64位整数,它可以容纳从-(2^63)到(2^63)-1的值。