why would i get an overflow error on this line:

MsgBox Trim(inv * 64)

when inv is only 671?

Re: overflow error by Greg

Greg
Tue May 24 16:32:57 CDT 2005

Try:
Sub Test()
Dim inv As Integer
inv = 671
MsgBox Trim(CLng(inv) * 64)

End Sub

and see the VB help file, subject "Trappable Errors"


--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

SonnyMaou wrote:
> why would i get an overflow error on this line:
>
> MsgBox Trim(inv * 64)
>
> when inv is only 671?



Re: overflow error by JE

JE
Tue May 24 16:33:57 CDT 2005

Because 671 * 64 = 42944, which is larger than the largest integer
(32767). VBA will cast the result as the largest of the two operands.
Since inv is presumably Dim'd as an integer and 64 fits into an integer,
VBA will cast the result as an integer. Hence the overflow.

There's almost never a need to use integers on modern computers (it can
actually waste processor cycles) - use long integers instead

Dim inv As Long

instead.

Alternatively, cast 64 as a long integer (&) or a double (#):

MsgBox Trim(inv * 64&)






In article <oNMke.598088$A81.14654@fe08.news.easynews.com>,
SonnyMaou <SendNoSpamToSonnyMaou@yahoo.com> wrote:

> why would i get an overflow error on this line:
>
> MsgBox Trim(inv * 64)
>
> when inv is only 671?

Re: overflow error by Greg

Greg
Tue May 24 17:16:28 CDT 2005

JE,

Where does one learn about all those #, $, & things?


--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

JE McGimpsey wrote:
> Because 671 * 64 = 42944, which is larger than the largest integer
> (32767). VBA will cast the result as the largest of the two operands.
> Since inv is presumably Dim'd as an integer and 64 fits into an
> integer, VBA will cast the result as an integer. Hence the overflow.
>
> There's almost never a need to use integers on modern computers (it
> can actually waste processor cycles) - use long integers instead
>
> Dim inv As Long
>
> instead.
>
> Alternatively, cast 64 as a long integer (&) or a double (#):
>
> MsgBox Trim(inv * 64&)
>
>
>
>
>
>
> In article <oNMke.598088$A81.14654@fe08.news.easynews.com>,
> SonnyMaou <SendNoSpamToSonnyMaou@yahoo.com> wrote:
>
>> why would i get an overflow error on this line:
>>
>> MsgBox Trim(inv * 64)
>>
>> when inv is only 671?



Re: overflow error by JE

JE
Tue May 24 17:29:29 CDT 2005

VBA Help - look at each data type:

For instance:

> Long data type
> A 4-byte integer ranging in value from -2,147,483,648 to
> 2,147,483,647. The ampersand (&) type-declaration character
> represents a Long in Visual Basic.

and it's helpful to know:

> type-declaration character
> A character appended to a variable name indicating the variable's
> data type.



In article <OdmMy4KYFHA.1040@TK2MSFTNGP10.phx.gbl>,
"Greg Maxey" <gmaxey@mvps.OscarRomeoGolf> wrote:

> Where does one learn about all those #, $, & things?
>

Re: overflow error by Greg

Greg
Tue May 24 17:35:52 CDT 2005

I humbled again. Thanks :-)


--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

JE McGimpsey wrote:
> VBA Help - look at each data type:
>
> For instance:
>
>> Long data type
>> A 4-byte integer ranging in value from -2,147,483,648 to
>> 2,147,483,647. The ampersand (&) type-declaration character
>> represents a Long in Visual Basic.
>
> and it's helpful to know:
>
>> type-declaration character
>> A character appended to a variable name indicating the variable's
>> data type.
>
>
>
> In article <OdmMy4KYFHA.1040@TK2MSFTNGP10.phx.gbl>,
> "Greg Maxey" <gmaxey@mvps.OscarRomeoGolf> wrote:
>
>> Where does one learn about all those #, $, & things?



Re: overflow error by SonnyMaou

SonnyMaou
Wed May 25 14:50:43 CDT 2005

JE McGimpsey wrote:

> Because... Hence the overflow.
>
> There's almost never a need to use integers on modern computers (it can
> actually waste processor cycles) - use long integers instead
>
> Dim inv As Long
>
> instead.
>
> Alternatively, cast 64 as a long integer (&) or a double (#):
>
> MsgBox Trim(inv * 64&)

Thanks, JE... Great info and advice!