Please see post #6. I found an easier way of doing this without needing to use Decimals.
Hi All,
I was inspired by a post by hwoarang over in the codebank to write a class (and a supporting bas) that I might actually use.
It's a class that provides the VBA LongLong type to VB6. Now, before everyone jumps on it, it's not "native" 8-byte integers, but it gets it all done as if it were. I'm sure it's slower than native 8-byte integers would be.
However, the only initial difference I can see from what I'm doing and what VBA does, is that I require the use of the "New" keyword when declaring variables. Here's some test code in a form:
As you can see, the usage is VERY close to the way you'd use VBA LongLongs.Code:
Option Explicit
Private Sub Form_Load()
Dim LL1 As New LongLong
Dim LL2 As New LongLong
Dim LL3 As New LongLong
'
' Some simple tests.
'
LL1 = 5
LL2 = LL1
MsgBox LL1
MsgBox LL2
MsgBox LL1 + LL2
MsgBox LL1 * LL2
MsgBox LL1 / LL2
MsgBox LL1 ^ LL2
LL3 = LL1 ^ LL2
MsgBox LL3
'
' Some more rigorous tests.
'
LL1 = CLngLng("9223372036854775807") ' Largest LongLong value in VBA.
MsgBox LL1
'LL1 = LL1 + 1 ' This will be an overflow.
LL1 = CLngLng("-9223372036854775807") ' (Almost) smallest LongLong value in VBA.
MsgBox LL1
LL1 = LL1 - 1 ' This not overflow.
MsgBox LL1
'LL1 = LL1 - 1 ' This will be an overflow.
Dim d As Double
d = 9.22337203685477E+18
LL1 = d
MsgBox LL1
'LL1 = LL1 * 2 ' This will overflow.
End Sub
I've attached a sample project which includes the Class that gets it done, along with a supporting BAS module. In the BAS module, there's a CLngLng function that'll convert about anything to a Decimal (with overflow checks at LongLong ranges). This can be directly placed into a LongLong declared variable (as those are actually handed back as Decimals also so that math natively works).
I'm open to whatever critiques/bugs people would like to make/report about any of this. Maybe after I've polished it some more, I'll post it in the codebank.
Regards,
Elroy

