How to do 64-Bit Integers in Visual Basic 6.0

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
 

Are 64-bit Integers possible to do in VB 6.0? Well, officially it’s a no I guess, but technically it’s a yes I guess. 🙂  Actually the VB Currency Type is 64 Bit. The problem with using this for Integer/Long based values is a Decimal point is inserted. But there is a way around this. The small piece of code below from Microsoft will work around this Currency type decimal point issue. The code will get the Currency variable’s value and change to a String while removing the decimal point. I know its not considered ‘elegant’ coding, but sometimes you have to do what you have to do to get around a limitation.


Private Function CurrToText(ByVal Value As Currency) As String

        Dim Temp As String, L As Long

        Temp = Format$(Value, “#.0000?)

        L = Len(Temp)

        Temp = Left$(Temp, L – 5) & Right$(Temp, 4)

        Do While Len(Temp) > 1 And Left$(Temp, 1) = "0? "

            Temp = Mid$(Temp, 2)

        Loop

        Do While Len(Temp) > 2 And Left$(Temp, 2) = "-0? "

            Temp = "-" & Mid$(Temp, 3)

        Loop

        CurrToText = Temp

    End Function

Now all you have to do it supply Currency the variable you want to convert. Example….


        Dim myCurrencyType As Currency

        Dim my64BitValue As String

        my64BitValue = CurrToText(myCurrencyType)

        MsgBox(my64BitValue)


That’s all there is to it.  Take care.

Jason