ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA Long data type overflow (https://www.excelbanter.com/excel-programming/282647-vba-long-data-type-overflow.html)

Jean Stax

VBA Long data type overflow
 
Hi !

The following code generates Overflow error:

Dim NumberP As Long
NumberP = 1078282205 * 31

According to MSDN:
Long variables are stored as signed 64-bit (8-byte) integers ranging
in value from -9,223,372,036,854,775,808 through
9,223,372,036,854,775,807.

What is going wrong there ?
Maybe VBA Long data size differs from VB Long data size ?

Thanks

keepITcool

VBA Long data type overflow
 
VBA long is 4byte(32bit) signed.

If you need larger numbers try Currency which is 8byte scaled integer
see VBA help DataType summary.



keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


(Jean Stax) wrote:

Dim NumberP As Long
NumberP = 1078282205 * 31



J.E. McGimpsey

VBA Long data type overflow
 
Different applications/compilers/environments do define data types
differently. For Excel (from XL/VBA Help):

Long Data Type

Long (long integer) variables are stored as signed 32-bit (4-byte) numbers
ranging in value from -2,147,483,648 to 2,147,483,647. The type-declaration
character for Long is the ampersand (&).



In article ,
(Jean Stax) wrote:

Hi !

The following code generates Overflow error:

Dim NumberP As Long
NumberP = 1078282205 * 31

According to MSDN:
Long variables are stored as signed 64-bit (8-byte) integers ranging
in value from -9,223,372,036,854,775,808 through
9,223,372,036,854,775,807.

What is going wrong there ?
Maybe VBA Long data size differs from VB Long data size ?

Thanks


Chip Pearson

VBA Long data type overflow
 
Jean,

Longs are 4-bytes (32-bits) ranging in value from -2,147,483,648 to
2,147,483,647 . Where did you find that definition in MSDN?


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Jean Stax" wrote in message
om...
Hi !

The following code generates Overflow error:

Dim NumberP As Long
NumberP = 1078282205 * 31

According to MSDN:
Long variables are stored as signed 64-bit (8-byte) integers ranging
in value from -9,223,372,036,854,775,808 through
9,223,372,036,854,775,807.

What is going wrong there ?
Maybe VBA Long data size differs from VB Long data size ?

Thanks




Tom Ogilvy

VBA Long data type overflow
 
http://msdn.microsoft.com/library/de...us/vblr7/html/
vadatlong.asp

Which includes a caution about VB6 Longs.
--
Regards,
Tom Ogilvy


Chip Pearson wrote in message
...
Jean,

Longs are 4-bytes (32-bits) ranging in value from -2,147,483,648 to
2,147,483,647 . Where did you find that definition in MSDN?


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Jean Stax" wrote in message
om...
Hi !

The following code generates Overflow error:

Dim NumberP As Long
NumberP = 1078282205 * 31

According to MSDN:
Long variables are stored as signed 64-bit (8-byte) integers ranging
in value from -9,223,372,036,854,775,808 through
9,223,372,036,854,775,807.

What is going wrong there ?
Maybe VBA Long data size differs from VB Long data size ?

Thanks







All times are GMT +1. The time now is 08:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com