Results 1 to 14 of 14

Thread: LongLong

Threaded View

  1. #1

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,909

    LongLong

    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:

    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
    
    As you can see, the usage is VERY close to the way you'd use VBA LongLongs.

    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
    Attached Files Attached Files
    Last edited by Elroy; Dec 2nd, 2016 at 02:39 PM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width