Overflow Error 
Author Message
 Overflow Error

Hi,

I'm tring to shift bit in VB, for this i found this article :
http://www.*-*-*.com/ {*filter*}/tip_13.htm

This article talk about a bug with : Value AND (2^31)
that crash with an overflow error

While using the workaround in the article i got the same
crash while using MOD and  \

I tried different type for tmpvalue and carrybit but got the same error

Thanks for your help

Dim tmpvalue As Double
Dim carrybit As Integer

' work
tmpvalue = 2 ^ 15
carrybit = tmpvalue \ 2

' Overflow
tmpvalue = 2 ^ 16
carrybit = tmpvalue \ 2

' work
tmpvalue = 2 ^ 30
carrybit = tmpvalue Mod 2

' Overflow
tmpvalue = 2 ^ 31
carrybit = tmpvalue Mod 2



Sun, 08 Aug 2004 16:41:49 GMT  
 Overflow Error
Bitwise AND, MOD and \ are all operators on integral datatypes
therefore they cannot handle anything larger than the maximum value
for a long (since this is the largest integral datatype in VB) 2^31-1.

There is no bug here just some poor documentation.

If you want a bit set function you can try the following:

Function IsBitSet(byval NumberToCheck as long, byval BitToCheck as
byte) as boolean

  const bit31 as long=&H80000000&

  'The <> 0 part is not strictly necessary but makes it clearer what
  ' is happening.
  Select Case BitToCheck
    Case 0 to 30
      IsBitSet = ((NumberToCheck AND 2 ^ BitToCheck) <> 0)
    Case 31
      IsBitSet = ((NumberToCheck AND bit31) <> 0)
    Case Else
      'Raise an error
  End Select

End Function

Also inline.

On Wed, 20 Feb 2002 08:41:49 -0000, "Y.LEROUX"

Quote:

>Hi,

>I'm tring to shift bit in VB, for this i found this article :
> http://www.*-*-*.com/ {*filter*}/tip_13.htm

>This article talk about a bug with : Value AND (2^31)
>that crash with an overflow error

>While using the workaround in the article i got the same
>crash while using MOD and  \

>I tried different type for tmpvalue and carrybit but got the same error

>Thanks for your help

>Dim tmpvalue As Double
>Dim carrybit As Integer

>' work
>tmpvalue = 2 ^ 15
>carrybit = tmpvalue \ 2

>' Overflow
>tmpvalue = 2 ^ 16
>carrybit = tmpvalue \ 2

carrybit is an integer max value = 2 ^ 15 - 1
Quote:

>' work
>tmpvalue = 2 ^ 30
>carrybit = tmpvalue Mod 2

>' Overflow
>tmpvalue = 2 ^ 31
>carrybit = tmpvalue Mod 2

tmpvalue cannot be converted to long for Mod operation.

Stephen Martin
EMSoft Solutions Inc.
Toronto, ON



Mon, 09 Aug 2004 00:00:38 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Error handling / Arithmetic overflow error

2. Overflow error, error number 6, in VB6 using Crystal Reports 7

3. Overflow Error ?????

4. Overflow Error#6

5. Data OverFlow Error Message

6. Is there a limit on a integer variable (overflow error)

7. Overflow error 3*15000

8. Overflow error - but can't see why ?

9. Overflow error

10. Overflow error & possible list box connection

11. Overflow error

12. Overflow Error 6

 

 
Powered by phpBB® Forum Software