开发者

VB6 Converting Long to Integer throwing overflow

开发者 https://www.devze.com 2023-04-08 21:07 出处:网络
I am trying to convert a long to an integer. I believe the value of the long is low enough to fit in the range on an integer.

I am trying to convert a long to an integer. I believe the value of the long is low enough to fit in the range on an integer.

I have the code:

'mapdc is a long
Debug.Print mapdc
Debug.Print CInt(mapdc)

The first line runs fine.开发者_运维百科 It outputs 1107367444. The second line however causing an overflow error to happen.

Any ideas? THANKS!!!!


A VB6 Integer data type is 16-bits. You are causing an overflow: The value of mapdc is greater than 32,767 which falls outside of the range of values supported by an Integer variable. For more information on VB6 data types see this MSDN page.


The range of a VB6 Integer type is -32,768 to 32,767. Obviously, your value falls outside of that range and overflows.

Data Types - VB 6 tutorial

MSDN Confirms by saying that a VB6 Integer corresponds to the .NET type of Int16 which has the same range:

Integer Data Type for Visual Basic 6.0 Users


Int in VB6 is 16 bit (range from -32,768 to 32,767). This link provides a comparison between VB6 with the .Net equivalents

0

精彩评论

暂无评论...
验证码 换一张
取 消