Re: Overflow



The problem is that VBA tries to calculate
162 * 207 as an Integer, and then convert
to the result to a Long. The first of these
steps causes the overflow. You can get
round this by forcing one of the values
to be a Long:

ll_test = 162& * 207
or
ll_test = CLng(162) * 207

Note that ll_test = clng(162 * 207) will fail,
for the same reason as in the original problem.


Andrew Taylor




Erik Beck Jensen wrote:
> Excel 2003 SP2
>
> Hello every body
>
>
> This little sub gives me a runtime overflow. Did I miss something?
>
>
>
>
> Sub ebj()
>
> Dim ll_test As Long
>
> ll_test = 162 * 207
>
>
> End Sub
>
>
>
> I would have expected ll_test to take a value = 33,534. A Long should be
> sufficient to hold that. If I change the declaration to Single or Variant I
> still get an overflow.
>
>
>
> Any suggestions?
>
>
>
>
>
> Best regards
>
> Erik

.



Relevant Pages

  • [NEWS] mnoGoSearch Vulnerable to a Buffer Overflow Vulnerability (ul, tmplt)
    ... mnoGoSearch is a full-featured SQL based ... Overflow in "ul" parameter: ... sub hex_to_int { ... # linux ix86 shellcode rip from phx.c by proton ...
    (Securiteam)
  • Re: Using IWin32Window to SetParent
    ... the error was an overflow that was happening on Handle.ToInt32 ... Int32, ByVal Parent As Int32) As Int32 ... Friend Overloads Sub Show ... > thing to do would be to debug the overflow exception. ...
    (microsoft.public.vsnet.ide)
  • Re: Overflow error in Progress Bar
    ... Rick (MVP - Excel) ... if any part of the calculation exceeds what an Integer can hold, then an overflow error is generated. ... So, in your sub, the ...
    (microsoft.public.excel.programming)
  • Re: Overflow error in Progress Bar
    ... if any part of the calculation exceeds what an Integer can hold, then an overflow error is generated. ... So, in your sub, the ... Dim i As Integer ...
    (microsoft.public.excel.programming)
  • Re: Bias in rand for excel 07
    ... that was statistically different from expectation. ... Sub SimplerVersion() ... "yttrias" wrote: ... There is no RANDfunction in VBA. ...
    (microsoft.public.excel.programming)