VB6 overflow error with large integers

前端 未结 3 1140
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-12 10:57

I am trying to set an integer value as such:

Dim intID as integer
intID = x * 10000

This works ok when x is 3 or less. But when

3条回答
  •  自闭症患者
    2021-02-12 11:43

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

    Long is the 32 bit type.

    However as a caveat, if you were to:

    Dim lngID As Long
    lngID = 4 * 10000
    

    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)
    

    Update:

    enter image description here

提交回复
热议问题