-
May 16th, 2021, 06:48 PM
#1
Thread Starter
Frenzied Member
How do I make addition overflow without error?
I want it to be able to overflow the &h7FFFFFFF boundary so that I can check for a negative number, to see if an overflow has occurred. While I can use On Error Resume Next and then check if an error happened using If Err.Number, the code used by VB6 for executing this error check is quite slow. It would be much faster, if I could just check for a negative number to see if an overflow had occurred. I know that I can disable integer overflow errors in an EXE compiled with VB6, by changing the compilation settings, but that doesn't effect VB6's behavior, and I would like to be able to run my program in VB6 to debug it before compiling it. I need to be able to run it in the IDE, and find some kind of maybe hacky code to trick VB6 into allowing an overflow without error. Is this possible?
-
May 16th, 2021, 07:01 PM
#2
Re: How do I make addition overflow without error?
-
May 16th, 2021, 08:43 PM
#3
Re: How do I make addition overflow without error?
I have an unsigned math library backed by a C dll that allows for that.
Supports overflow and unsigned vals for byte, int, long, and 64 bit numbers
https://github.com/dzzie/libs/tree/master/vb6_utypes
Code:
Dim x As New ULong
x = &H7FFFFFFF
Debug.Print x '2147483647
Set x = x.Add(1)
Debug.Print x '-2147483648
Debug.Print x.toString(mUnsigned) '2147483648
Debug.Print x.toString(mHex) '80000000
Dim z As Long 'sanity check
z = &H80000000
Debug.Print z '-2147483648
Last edited by dz32; May 16th, 2021 at 08:47 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|