How can I have unsigned Integers and Longs in VB6?-VBForums
Results 1 to 23 of 23

Thread: How can I have unsigned Integers and Longs in VB6?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Posts
    526

    How can I have unsigned Integers and Longs in VB6?

    I know there are ONLY signed versions of the 2-byte Integer and 4-byte Long in VB6. But I have a burning question. Is there any DLL file that adds unsigned Integer and unsigned Long capabilities to VB6? If Microsoft hasn't made one, has any computer programing hobbiest made such a DLL file? If there is one, where can I download it?

  2. #2
    Addicted Member Xiphias3's Avatar
    Join Date
    Jan 2009
    Location
    Clarendon, Jamaica
    Posts
    188

    Re: How can I have unsigned Integers and Longs in VB6?

    hmmmmmm... Not sure about the DLL part, but if you want more memory space use larger data types such a Currency and Double. Otherwise, you might need mathematical help to implement DataTypes as User Defined Types in VB6. In any case:

    I think your talking about something like this.
    Code:
    Private Type LARGE_INTEGER
    	lowpart As Long
    	highpart As Long
    End Type
    Unfortunately, i dont understand how id implement something like this, as my mathematical skills havent yet reached fully into logic gates and bitshifting.

    Using Currency DataType for storing integer type values that require more than 4 bytes (VB6 Long). Thanks to Randy Birch for enlightening me a while back.

    Code:
    Private Declare Function GetDiskFreeSpaceEx Lib "kernel32.dll" Alias "GetDiskFreeSpaceExA" (ByVal lpDirectoryName As String, ByRef lpFreeBytesAvailableToCaller As Any, ByRef lpTotalNumberOfBytes As Any, ByRef lpTotalNumberOfFreeBytes As Any) As Long
    
    Private Function getOutputDirDriveFreeSpace()
        Dim cFreeSpace As Currency, cTotalSpace As Currency, lRet As Long
        
        lRet = GetDiskFreeSpaceEx("C:\", ByVal 0, cTotalSpace, cFreeSpace)
        If (lRet <> 0) Then
            'Curreny has a precision of 4 decimal places, so multiplay by 10000 to move the decimal point to the end
            cFreeSpace = (cFreeSpace * 10000) / 1024# / 1024# / 1024#
            cTotalSpace = (cTotalSpace * 10000) / 1024# / 1024# / 1024#
            Call MsgBox(Format(cFreeSpace, "#,##0.00") + " GB / " + Format(cTotalSpace, "#,##0.00") + " GB")
        Else
            Call MsgBox("Invalid Dir")
        End If
    End Function
    Last edited by Xiphias3; Jul 30th, 2009 at 07:16 AM. Reason: ;]

  3. #3
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,430

    Re: How can I have unsigned Integers and Longs in VB6?

    You can write functions that simulate unsigned integer math using signed integer types. Although any such function would be much slower than native unsigned support it would still probably be faster than making a call to a DLL (if such a DLL existed).

    Here are a couple of rather hefty but speedy functions for unsigned addition and multiplication of Longs. There are much simpler techniques which involve coercing/casting to other types.
    vb Code:
    1. Public Function uAdd(ByVal A As Long, ByVal B As Long) As Long
    2.  Dim lOr As Long, lAnd As Long, P As Long
    3.  
    4.  lOr = (A Or B) And &HC0000000
    5.  
    6.  If lOr Then 'it might overflow
    7.    lAnd = (A And B) And &HC0000000
    8.    P = (A And &H3FFFFFFF) + (B And &H3FFFFFFF)
    9.    
    10.    Select Case lAnd 'the last two bits common to both numbers
    11.      Case 0&
    12.        If (P And lOr) Then
    13.          If lOr < 0 Then uAdd = (P And &H3FFFFFFF) Else uAdd = (P And &H3FFFFFFF) Or &H80000000
    14.        Else
    15.          uAdd = P Or lOr
    16.        End If
    17.      Case &H80000000: If (P And lOr) Then uAdd = (P And &H3FFFFFFF) Or &H80000000 Else uAdd = P Or (lOr And &H40000000)
    18.      Case &H40000000: If (lOr < 0) Then uAdd = P Else uAdd = P Or &H80000000
    19.      Case Else: uAdd = P Or &H80000000
    20.    End Select
    21.    
    22.  Else 'it won't overflow
    23.    uAdd = A + B
    24.  End If
    25.  
    26. End Function
    27.  
    28.  
    29. Public Function uMult(ByVal A As Long, ByVal B As Long) As Long
    30. 'Unsigned 32bit integer multiplication with signed 32bit numbers
    31. 'Returns a signed 32bit number as if it were unsigned.
    32. 'Will overflow without error
    33.  
    34. 'It might look ugly, but it's much faster than converting Longs to Doubles and back (when compiled)
    35.  
    36. Dim A1 As Long, A2 As Long
    37. Dim B1 As Long, B2 As Long
    38. Dim P As Long, P2 As Long
    39.  
    40.   A1 = A And &H7FFF&
    41.   B1 = B And &H7FFF&
    42.   A2 = (A And &H3FFF8000) \ &H8000& 'quicker than... (A \ &h8000&) And &H7FFF&
    43.   B2 = (B And &H3FFF8000) \ &H8000& 'quicker than... (A \ &h8000&) And &H7FFF&
    44.  
    45.   'multiply first 2 bits of A by last 2 bits of B
    46.   Select Case B And &HC0000000
    47.     Case 0&
    48.     Case &H40000000
    49.       Select Case A And 3&
    50.         Case 0&:
    51.         Case 1&: P = &H40000000
    52.         Case 2&: P = &H80000000
    53.         Case 3&: P = &HC0000000
    54.       End Select
    55.     Case &H80000000
    56.       If A And 1& Then P = &H80000000
    57.     Case Else
    58.       Select Case A And 3&
    59.         Case 0&:
    60.         Case 1&: P = &HC0000000
    61.         Case 2&: P = &H80000000
    62.         Case 3&: P = &H40000000
    63.       End Select
    64.   End Select
    65.  
    66.   'multiply first 2 bits of B by last 2 bits of A
    67.   Select Case A And &HC0000000
    68.     Case 0&
    69.     Case &H40000000
    70.       Select Case B And 3&
    71.         Case 0&                                                                          'P+0
    72.         Case 1&: If P And &H40000000 Then P = P Xor &HC0000000 Else P = P Or &H40000000  'P+&H40000000
    73.         Case 2&: P = P Xor &H80000000                                                    'P+&H80000000
    74.         Case 3&: If P And &H40000000 Then P = P Xor &H40000000 Else P = P Xor &HC0000000 'P+&H40000000+&H80000000
    75.       End Select
    76.     Case &H80000000
    77.       If B And 1& Then P = P Xor &H80000000                                             'P+&H80000000
    78.     Case Else
    79.       Select Case B And 3&
    80.         Case 0&                                                                          'P+0
    81.         Case 1&: If P And &H40000000 Then P = P Xor &H40000000 Else P = P Xor &HC0000000 'P+&H40000000+&H80000000
    82.         Case 2&: P = P Xor &H80000000                                                    'P+&H80000000
    83.         Case 3&: If P And &H40000000 Then P = P Xor &HC0000000 Else P = P Or &H40000000  'P+&H40000000
    84.       End Select
    85.   End Select
    86.  
    87.   'multiply bits 16 and 17 of A and B
    88.   Select Case (A2 * B2) And &H3&
    89.     Case 0&                                                                              'P+0
    90.     Case 1&: If P And &H40000000 Then P = P Xor &HC0000000 Else P = P Or &H40000000      'P+&H40000000
    91.     Case 2&: P = P Xor &H80000000                                                        'P+&H80000000
    92.     Case Else: If P And &H40000000 Then P = P Xor &H40000000 Else P = P Xor &HC0000000   'P+&H40000000+&H80000000
    93.   End Select
    94.  
    95.   'multiply first 15 bits of A and B
    96.   P = (A1 * B1) Or P
    97.  
    98.   'multiply first 15 bits of A with bits 16 to 30 of B
    99.   P2 = A1 * &H2&
    100.   If P2 And &H10000 Then P2 = ((P2 And &HFFFF&) * &H8000&) Or &H80000000 Else P2 = (P2 And &HFFFF&) * &H8000&
    101.   P = uAdd(P, P2)
    102.  
    103.   'multiply first 15 bits of B with bits 16 to 30 of A
    104.   P2 = A2 * &H1&
    105.   If P2 And &H10000 Then P2 = ((P2 And &HFFFF&) * &H8000&) Or &H80000000 Else P2 = (P2 And &HFFFF&) * &H8000&
    106.   uMult = uAdd(P, P2)
    107.  
    108. End Function

  4. #4
    Addicted Member Xiphias3's Avatar
    Join Date
    Jan 2009
    Location
    Clarendon, Jamaica
    Posts
    188

    Re: How can I have unsigned Integers and Longs in VB6?

    Quote Originally Posted by Milk View Post
    You can write functions that simulate unsigned integer math using signed integer types. Although any such function would be much slower than native unsigned support it would still probably be faster than making a call to a DLL (if such a DLL existed).

    Here are a couple of rather hefty but speedy functions for unsigned addition and multiplication of Longs. There are much simpler techniques which involve coercing/casting to other types.
    vb Code:
    1. Public Function uAdd(ByVal A As Long, ByVal B As Long) As Long
    2.  Dim lOr As Long, lAnd As Long, P As Long
    3.  
    4.  lOr = (A Or B) And &HC0000000
    5.  
    6.  If lOr Then 'it might overflow
    7.    lAnd = (A And B) And &HC0000000
    8.    P = (A And &H3FFFFFFF) + (B And &H3FFFFFFF)
    9.    
    10.    Select Case lAnd 'the last two bits common to both numbers
    11.      Case 0&
    12.        If (P And lOr) Then
    13.          If lOr < 0 Then uAdd = (P And &H3FFFFFFF) Else uAdd = (P And &H3FFFFFFF) Or &H80000000
    14.        Else
    15.          uAdd = P Or lOr
    16.        End If
    17.      Case &H80000000: If (P And lOr) Then uAdd = (P And &H3FFFFFFF) Or &H80000000 Else uAdd = P Or (lOr And &H40000000)
    18.      Case &H40000000: If (lOr < 0) Then uAdd = P Else uAdd = P Or &H80000000
    19.      Case Else: uAdd = P Or &H80000000
    20.    End Select
    21.    
    22.  Else 'it won't overflow
    23.    uAdd = A + B
    24.  End If
    25.  
    26. End Function
    27.  
    28.  
    29. Public Function uMult(ByVal A As Long, ByVal B As Long) As Long
    30. 'Unsigned 32bit integer multiplication with signed 32bit numbers
    31. 'Returns a signed 32bit number as if it were unsigned.
    32. 'Will overflow without error
    33.  
    34. 'It might look ugly, but it's much faster than converting Longs to Doubles and back (when compiled)
    35.  
    36. Dim A1 As Long, A2 As Long
    37. Dim B1 As Long, B2 As Long
    38. Dim P As Long, P2 As Long
    39.  
    40.   A1 = A And &H7FFF&
    41.   B1 = B And &H7FFF&
    42.   A2 = (A And &H3FFF8000) \ &H8000& 'quicker than... (A \ &h8000&) And &H7FFF&
    43.   B2 = (B And &H3FFF8000) \ &H8000& 'quicker than... (A \ &h8000&) And &H7FFF&
    44.  
    45.   'multiply first 2 bits of A by last 2 bits of B
    46.   Select Case B And &HC0000000
    47.     Case 0&
    48.     Case &H40000000
    49.       Select Case A And 3&
    50.         Case 0&:
    51.         Case 1&: P = &H40000000
    52.         Case 2&: P = &H80000000
    53.         Case 3&: P = &HC0000000
    54.       End Select
    55.     Case &H80000000
    56.       If A And 1& Then P = &H80000000
    57.     Case Else
    58.       Select Case A And 3&
    59.         Case 0&:
    60.         Case 1&: P = &HC0000000
    61.         Case 2&: P = &H80000000
    62.         Case 3&: P = &H40000000
    63.       End Select
    64.   End Select
    65.  
    66.   'multiply first 2 bits of B by last 2 bits of A
    67.   Select Case A And &HC0000000
    68.     Case 0&
    69.     Case &H40000000
    70.       Select Case B And 3&
    71.         Case 0&                                                                          'P+0
    72.         Case 1&: If P And &H40000000 Then P = P Xor &HC0000000 Else P = P Or &H40000000  'P+&H40000000
    73.         Case 2&: P = P Xor &H80000000                                                    'P+&H80000000
    74.         Case 3&: If P And &H40000000 Then P = P Xor &H40000000 Else P = P Xor &HC0000000 'P+&H40000000+&H80000000
    75.       End Select
    76.     Case &H80000000
    77.       If B And 1& Then P = P Xor &H80000000                                             'P+&H80000000
    78.     Case Else
    79.       Select Case B And 3&
    80.         Case 0&                                                                          'P+0
    81.         Case 1&: If P And &H40000000 Then P = P Xor &H40000000 Else P = P Xor &HC0000000 'P+&H40000000+&H80000000
    82.         Case 2&: P = P Xor &H80000000                                                    'P+&H80000000
    83.         Case 3&: If P And &H40000000 Then P = P Xor &HC0000000 Else P = P Or &H40000000  'P+&H40000000
    84.       End Select
    85.   End Select
    86.  
    87.   'multiply bits 16 and 17 of A and B
    88.   Select Case (A2 * B2) And &H3&
    89.     Case 0&                                                                              'P+0
    90.     Case 1&: If P And &H40000000 Then P = P Xor &HC0000000 Else P = P Or &H40000000      'P+&H40000000
    91.     Case 2&: P = P Xor &H80000000                                                        'P+&H80000000
    92.     Case Else: If P And &H40000000 Then P = P Xor &H40000000 Else P = P Xor &HC0000000   'P+&H40000000+&H80000000
    93.   End Select
    94.  
    95.   'multiply first 15 bits of A and B
    96.   P = (A1 * B1) Or P
    97.  
    98.   'multiply first 15 bits of A with bits 16 to 30 of B
    99.   P2 = A1 * &H2&
    100.   If P2 And &H10000 Then P2 = ((P2 And &HFFFF&) * &H8000&) Or &H80000000 Else P2 = (P2 And &HFFFF&) * &H8000&
    101.   P = uAdd(P, P2)
    102.  
    103.   'multiply first 15 bits of B with bits 16 to 30 of A
    104.   P2 = A2 * &H1&
    105.   If P2 And &H10000 Then P2 = ((P2 And &HFFFF&) * &H8000&) Or &H80000000 Else P2 = (P2 And &HFFFF&) * &H8000&
    106.   uMult = uAdd(P, P2)
    107.  
    108. End Function
    Haha! Yea, everything here i dont understand.

  5. #5
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: How can I have unsigned Integers and Longs in VB6?

    In many cases you can just use Long instead of unsigned Integer and Currency is probably the next most efficient replacement for unsigned Long. However, if you need to save to a file or manipulate memory things are different... there are tons of case dependant situatations.

    So the burning question is: what are you trying to achieve that would require unsigned Integer & Long?

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Posts
    526

    Re: How can I have unsigned Integers and Longs in VB6?

    I know VB6 has these DataTypes for integer numbers:
    Byte (1 byte of unsigned data)
    Integer (2 bytes of signed data)
    Long (4 bytes of signed data)

    What I need add to those basic DataTypes are these:
    UInteger (2 bytes of unsigned data)
    ULong (4 bytes of unsigned data)

    Why? Why not use a Long instead of Integer for unsigned "integers", or Currency instead of Long for unsigned "longs"? Well I have a very good reason. This is inefficient in file size. If I have a number that only needs 2 bytes of data, I shouldn't have to use 4 bytes. If I have a number that only needs 4 bytes, I shouldn't have to use 8 bytes. This will save file space, and in many cases I'll be writing to a file that is meant to be read by an already made program who's specifications REQUIRE an unsigned integer or unsigned long. If I use for example a long instead of an unsigned integer, the program will NOT correctly read the file. I need a fix to that. User defined types don't add Datatypes to those natively in VB. That is
    Code:
    Public type UInteger
    HighByte as byte
    LowByte as byte
    End type
    can NOT be written to with
    Code:
    Dim x as UInteger
    x = 60000
    because it isn't really a DataType, it is just a user defined type with 2 parts, each of which is a byte.

    What I need is a DLL file (or any other addon that I could use, whether official from MS or unofficial from a "hacker", I don't really care) that adds UInteger and ULong into Visual Basic as basic DataTypes, so that the list of DataTypes VB6 can handle would become:

    Byte (1 byte of unsigned data)
    Integer (2 bytes of signed data)
    UInteger (2 bytes of unsigned data)
    Long (4 bytes of signed data)
    ULong (4 bytes of unsigned data)


    If anyone on this site knows of such an addon and the site that I could download it from, please link to that site.

  7. #7
    VBaholic & Loving It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    GetWindowRect()
    Posts
    12,836

    Re: How can I have unsigned Integers and Longs in VB6?

    Have you looked at Milk's posting above? If you don't want to expand the byte size, then you'll have to use conversion functions that convert both ways to signed/unsigned from unsigned/signed.

    For example, an Integer value of Max(Int Positive Value)+1 is an overflow. But converted to unsigned, it becomes a negative value in VB. However, in any app that expects UINT will see that negative VB integer as a positive UINT, since UINT can't be negative anyway.

    Edited: here are some I have used in the past. Double check it, I had to modify some things when I pulled it out of an existing project on PSC. That project of mine includes a bunch of bit manipulation routines -- worth checking out if you want to expand your knowledge.
    Code:
    Private Const MaxUnsignedLongAnd1 As Double = 4294967296#
    Private Const MaxSignedLongAnd1 As Double = 2147483648#
    Private Const MaxUnsignedInt As Long = 65536
    Private Const MaxSignedIntAnd1 As Long = 32768
    
    Public Function SignedIntegerToUnsigned(ByVal theValue As Integer) As Long
        ' function converts a signed integer to an unsigned Long
        SignedIntegerToUnsigned = (theValue And &HFFFF&)
    End Function
    Public Function UnsignedIntegerToSigned(ByVal theValue As Long) As Integer
        ' function converts a Long to a signed integer
        ' if the passed value contains more than 16 usable bits, we can't scrunch 16+ into a 16bit variable
        If theValue < 0& Or theValue > MaxUnsignedInt  - 1& Then Exit Function ' overflow
        If theValue < MaxSignedIntAnd1 Then
            UnsignedIntegerToSigned = theValue
        Else
            UnsignedIntegerToSigned = theValue - MaxUnsignedInt 
        End If
    End Function
    Public Function SignedLongToUnsigned(ByVal theValue As Long) As Double
        ' function converts a signed long to an unsigned Double
        If (theValue And &H80000000) Then
            SignedLongToUnsigned = theValue + MaxUnsignedLongAnd1
        Else
            SignedLongToUnsigned = theValue
        End If
    End Function
    Public Function UnsignedLongToSigned(ByVal theValue As Double) As Long
        ' function converts a Double to a signed Long
        
        ' if the passed value contains more than 32 usable bits, we can't scrunch 32+ into a 32bit variable
        If theValue < 0# Or theValue > MaxUnsignedLongAnd1 Then Exit Function  ' overflow
        If theValue < MaxSignedLongAnd1 Then
            UnsignedLongToSigned = theValue
        Else
            UnsignedLongToSigned = theValue - MaxUnsignedLongAnd1
        End If
    End Function
    Last edited by LaVolpe; Jul 30th, 2009 at 08:02 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VBA Control Arrays} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Posts
    526

    Re: How can I have unsigned Integers and Longs in VB6?

    Well I still believe there must be some addon somewhere I can install that will give me the desired effect. I don't want to have to type in all that code JUST to set it up for using unsinged numbers. If I do that, every program I make I'll have to waste time typing ALL that in just for preparing data types. That time would be better spent typing in the ACTUAL program code.

  9. #9
    VBaholic & Loving It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    GetWindowRect()
    Posts
    12,836

    Re: How can I have unsigned Integers and Longs in VB6?

    All that code? Really? Ummm, if you create a class that contains the functions you want, you then only have to add the class to your new projects. If you add all that code to a module, then you'd only have to add the module to your new projects. Of course you would have to call the functions. That is one of the purposes of modules and classes -- reusability.
    Insomnia is just a byproduct of, "It can't be done"

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VBA Control Arrays} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10
    Hyperactive Member
    Join Date
    Aug 2006
    Location
    TeXaS
    Posts
    483

    Re: How can I have unsigned Integers and Longs in VB6?

    why would you type all that code? you copy/paste it.

  11. #11
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,430

    Re: How can I have unsigned Integers and Longs in VB6?

    If all you are doing is writing these unsigned values to file and you don't actually want to perform any operations with them then you don't really need them as data types.

    Hex is written unsigned, the illegal (for integer) x=60000 could be written legally as x=&HEA60.

    Alternatively simple short functions could be used to assign values. eg..
    Code:
    Public Function UInt(ByVal value As Long) As Integer
        UInt = value And &H7FFF&
        If (value And &H8000&) Then UInt = UInt + &H8000
    End Function
    Edit: the same function is in Lavolpes code.
    Last edited by Milk; Jul 30th, 2009 at 10:30 PM.

  12. #12
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: How can I have unsigned Integers and Longs in VB6?

    This post is supported by the One Liners Community International.

    16 lowest bits from Long to Integer:
    UInt = (Value And &H7FFF&) Or ((Value And &H8000&) <> 0 And &H8000)

    Integer bits copied to Long:
    Value = UInt And &HFFFF&

    Internally you can handle the Long (just need to ensure you stay within valid 16 bit range). For output you do that simplish math and you can do it inline. Inline code is a lot faster than calling functions. It may not look as pretty as you wanted, but you're asking for a feature that is not natively available in any easy way.

    There are some other options though. If you know ASM or C, you can use ThunderVB add-on and write unsigned math. Just remember that when you're trying to display the variable in VB it shows it signed. You can still use the methods above to workaround that issue.

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Posts
    526

    Re: How can I have unsigned Integers and Longs in VB6?

    Quote Originally Posted by Merri View Post
    It may not look as pretty as you wanted, but you're asking for a feature that is not natively available in any easy way.
    There must be some good hacker out there who's figured out how to add this functionality into VB6 by now, as VB6 has been out for a long time. All I need is a link to this hacker's site or his email address so I can ask him to give me a hacked EXE of Visual Basic with this added functionality.

  14. #14
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: How can I have unsigned Integers and Longs in VB6?

    ThunderVB is your best shot and gives you the functionality.

    The problem with your assumption is that nobody of us has heard of such a person who has done that. And most of us who have replied to you have been around for a pretty long time, seeing the rise and decline of VB6. Are you really sure you want to do this in VB6? Also, if you're so keen to insist on getting this functionality why you're not gaining yourself the knowledge on how to do it? Or you could always make an executable that reads through a compiled VB6 executable and changes all signed integer machine code instructions to unsigned versions :P

    I've always been able to workaround the signed/unsigned issue in practical applications. Even if I have missed unsigned integers I have also missed bit shifting and many other features. VB6 wasn't meant to be a fully capable programming environment, it is first and foremost a tool that lets you do interface quickly. Personally I've been kind of hacking around some things for years and looking for improved performance, but making modifications to the executable or compiler has been out of my interest: I wanted interoperability (ie. the code I post should work in any installation of VB6 as-is).

  15. #15
    VBaholic & Loving It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    GetWindowRect()
    Posts
    12,836

    Re: How can I have unsigned Integers and Longs in VB6?

    And there are such functionalities: DLLs people have already created. Google, search PSC and other sites. If you don't want to write the necessary code, nor want to create your own module/class that can be re-used over and over again, then include/reference the DLL you find.
    Insomnia is just a byproduct of, "It can't be done"

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VBA Control Arrays} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Posts
    526

    Re: How can I have unsigned Integers and Longs in VB6?

    Quote Originally Posted by Merri View Post
    ThunderVB is your best shot and gives you the functionality.
    I just checked the ThunderVB website, but can't find any download links for ThunderVB or ThunderASM. I can only find a description of it. There are links to download other stuff though. The site is not in English for the most part, so I can't really navigate it well.

    Could you please provide a link to download Thunder VB and ThunderASM

  17. #17
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: How can I have unsigned Integers and Longs in VB6?

    I can see the site only in English. If you search for the word "download" on the page I linked to the first thing you find is a link to the download page.


    Also a note on ThunderVB: it compiles ASM and C as inline code, and if you make a function that only contains ASM or C it will be compiled as inline code everywhere that function is being called from. This means you have no speed loss that you would have with similar VB6 only methods, and are able to make very simple custom math functions, bitwise handling such as bitshifting etc. - and they even provide a premade stuff that do things like that.
    Last edited by Merri; Jul 31st, 2009 at 03:12 PM.

  18. #18

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Posts
    526

    Re: How can I have unsigned Integers and Longs in VB6?

    Quote Originally Posted by Merri View Post
    I can see the site only in English. If you search for the word "download" on the page I linked to the first thing you find is a link to the download page.


    Also a note on ThunderVB: it compiles ASM and C as inline code, and if you make a function that only contains ASM or C it will be compiled as inline code everywhere that function is being called from. This means you have no speed loss that you would have with similar VB6 only methods, and are able to make very simple custom math functions, bitwise handling such as bitshifting etc. - and they even provide a premade stuff that do things like that.
    Actually I thought ThunderASM (not ThunderVB) is what compiled ASM and C. I thought ThunderVB just made it easier to install plugins in VB. By the way, does this Thunder stuff just call actual compilers (which have to be downloaded separately), or does it do the compiling on it's own? And also, once I've defined a C or ASM function, how do I then use it in VB? Are there special commands? Or do I use it the same way I would use a VB function?

  19. #19
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: How can I have unsigned Integers and Longs in VB6?

    All your questions are answered within the link; I feel it unnecessary to repeat the same in different words. Also, I don't have VB6 installed at the moment (new computer) and I haven't had ThunderVB installed in two years or so.

    This is the linked page as I can see it:
    Code:
    ThunderVB
    
    ThunderVB is an add-in for VB6. ThunderVB let's you embed Asm and C instructions directly in you VB source programs. Furthermore ThunVB let's you create a true StdCall Dlls. Moreover ThunVB can extend VB IDE to a basic Asm/C code editor. That means it can do syntax-highlighting of Asm/C keywords and supports intelli-sense for InlineAsm code as well.
    We have stopped ThunVB developing because we think the last release is quite stable and we don't have time to work on it.
    Sorry, but enjoy the last release and happy Asm/C coding.
    Visual Basic will live forever...
    
    MENU
    
    # ThunderVB
    
    
    # ThunderAsm
    # ThunderIDE+
    # ThunderDll
    
    
    # Packer
    
    
    # Speed Hacks
    # VB Internals
    
    
    # Homepage on SF .NET
    # Screenshots
    # Download
    # Questions about Asm/C/Dll coding
    # Bugs
    
    
    System requirements
    
    # Windows 2000/XP
    # Visual Basic 6 with Service Pack 6
    
    
    You can get Service Pack 6 here.
    ThunderVB
    aka ThunVB is a core part - it's a container for plugins. ThunVB can load and unload plugins. Also it offers wide range of useful functions that can other plugins freely use. For example API hooking, to SubClass any VB IDE's window, manipulate VB IDE's window, multi-language support and many more low-level functions.
    Menu
    ThunderAsm
    aka ThunAsm allows to write Asm and C code directly into VB code and compile it. ThunAsm supports MASM, FASM and NASM syntax.
    To compile InlineAsm code you will need Masm. You can get MASM 6.14 here.
    Unfortunately, the version 6.14 doesn't support SIMD but MASM 6.15 and higher does. If you want to use SIMD, then get MASM 6.15 here.
    
    And to compile InlineC code you will need C compiler. You can get it for free here.
    
    Hint - If you want to link smaller and faster apps, then replace linker that is shipped with VB6 with a newer linker that is shipped with VS2003.
    
    Writting InlineAsm code is pretty straigthforward. See the code below it's a simple Asm function.
    
       Public Function Return10() As Long
    
       '#asm'
       '#asm'  mov eax, 10
       '#asm'  ret
       '#asm'
    
       End Function
    
    That's a function that returns value 10. As you can see, Asm code is written straight to the VB's code and the code is prefixed by the tag '#asm'.
    
    And now similar C function.
    
       Public Function Return10() As Long
    
       '#c'
       '#c' long Return10() {
       '#c'    return 10;
       '#c' }
       '#c'
    
        End Function
    
    Again, C code is written straight to the VB's code and the code is prefixed by the tag '#c'.
    
    Now come code samples that will explain basic Asm/C coding strategies. For example calling API from Asm/C code, declaring Asm/C variables, accessing VB arrays/strings from Asm/C code and many others important things.
    
    Download all Asm code samples
    Download all C code samples
    Menu
    ThunderIDE+
    aka ThunIDE can highlight Asm and C code that is written in VB IDE. You can choose your own colours for Asm/C keywords. Check the screenshots to see it on your own eyes. It looks really cool.
    Menu
    ThunderDll
    aka ThunDll can compile Dll libraries. Dll's can export functions, you can change Base-Address, change name of EntryPoint and the Dll's can contain GUI (Forms) as well. The Dll's can be called from any language (C, Asm, Delphi...VB).
    To compile StdCall Dll's you will need ThunderAsm. Be shure that during linking is ThunderAsm loaded.
    
    Download all Dll code samples
    Menu
    Packer
    This tool can compress files after compilation. You can use your favourite packer and specify its command line that will be used for packing executable files or dll's after linking.
    Menu
    Speed Hacks
    We've coded several InlineAsm fucntions that beat their VB's counterparts. Get fast InStr, StrComp and other string and math fucntions right here.
    
    # Math Funtions Sqrt (FPU, SSE and 3Dnow variants)
    # Long to Single and Long to Double conversion
    # Integer to Single and Integer to Double conversion
    # VB functions Sng, Fix, Clng, Csng and Cdbl
    
    
    # Sorting Algorithms QuickSort and QSort
    # SelectSort, InsertSort, BubbleSort and CombSort
    # ShellSort and HeapSort
    
    # BinarySearch
    
    
    # String Functions Asc, AscW
    # Chr, ChrW
    # InStr
    # LCase, UCase
    # Left, Right
    # Len (only for Strings)
    # Mid
    # StrReverse
    # Trim, LTrim, RTrim
    
    
    # Miscellaneous string functions Boyer-Moore-Horspool String Search
    
    
    # Memory Functions Common string functions ObjPtr
    # StrPtr
    # VarPtr (only for Longs, Integers, Bytes and Strings)
    
    
    # Miscellaneous memory functions CopyMemory (based on MMX and SSE)
    
    
    Download all Speed Hacks
    Menu
    VB Internals
    We have discovered some interesting things about VB...
    # ThunRTMain secrets
    
    Some basic things about ThunRTMain.
    
    # Undocumented Memory Functions
    
    There are 2 undocumented memory functions in msvbvm60.dll - __vbaCopyBytes and __vbaCopyBytesZero. This essay explains how they work and what for they can be used.
    
    # Align VB Arrays
    
    I've coded a simple routine that can align array of Long's to 16, 32, 64 and 128 byte boundaries. This can be usefull when dealing with SIMD.
    
    Download all VB Internals articles
    Menu
    
    
    ThunderVB Development Team
    drkIIRaziel, Libor a Readwulf

  20. #20

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Posts
    526

    Re: How can I have unsigned Integers and Longs in VB6?

    Unfortunately I have to freaking download C++ 2008 Express to use the C functionality of ThunderASM. When making something like ThunderASM they really need to start including the entire C library with their own program as part of a package, so one doesn't have to make additional downloads. Besides I would NEVER use C++ or any other form of C on its own so I shouldn't have to install the entire stinking C++ software. I would ONLY use C programing through ThunderASM to use in visual basic, as VB is my primary programing language.

  21. #21
    New Member
    Join Date
    Aug 2011
    Posts
    9

    Re: How can I have unsigned Integers and Longs in VB6?

    I have the same problem
    I think the person who asked the question wants to get back a value from a Api
    You all respond with conversion functions in VB to get the unsigned long variable. etc.,
    But I think the question of who asked the question was the same as mine:
    What data type for the Api's return values without get an overflow?

    example
    WmiService.ExecQuery("Select * from Win32_DiskDrive", , 48)
    Class Win32_DiskDrive returns many values uint16, uint32, uint64


    For example, if I declare

    Public Type UInt32
    MyUInt32 As Long
    End Type

    both are signed numbers 32 bits (4 bytes), so it should be good
    Except that

    UInt32 is From 0 To 4,294,967,295.
    instead
    Long is From -2.147.483.648 To 2.147.483.647.

    The same amount of numbers, 4,294,967,295 , but in different range, if the Api returned , for example, 3.147.483.647 .The long will give Overflow..........

    Can I use a larger type, which occupies more bytes?

    For example, if I declare

    Public Type UInt32
    MyUInt32 As currency ' Currency is numer 64 bit (8 byte)
    End Type

    Beyond the waste of ram, MyUInt32 may contain 3.147.483.647 without giving Overflow
    But the fact that UInt32 is 32 bit (4 byte) and Currency is a 64 bit (8 byte). will cause me problems?

    I am very grateful for your attention

    Please help me not having to throw away all my knowledge in vb6, to continue programming in VB6 I need to use the Api,

  22. #22
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,430

    Re: How can I have unsigned Integers and Longs in VB6?

    This might be better off in its own thread, you can always link to other threads you feel they are related.

    If the API expects a type of 4 bytes you must give it a type of 4 bytes.

    With the example you give the Long will not overflow but rather than having a value of 3'147'483'647 it will have a value of -1'147'483'649.

    You can deal with this by checking if the return is negative and if so coerce it to a type such as Currency and then add 4'294'967'296 to it to get the value you want.
    Code:
      Dim myLong As Long, myCur As Currency
      myLong = APIFunctionThatReturnsUInt32()
      myCur = CCur(myLong)
      If myCur < 0 Then
         myCur = myCur + 4294967295@
      End If
    W o t . S i g

  23. #23
    New Member
    Join Date
    Aug 2011
    Posts
    9

    Re: How can I have unsigned Integers and Longs in VB6?

    Quote Originally Posted by Milk View Post
    This might be better off in its own thread, you can always link to other threads you feel they are related.

    If the API expects a type of 4 bytes you must give it a type of 4 bytes.

    With the example you give the Long will not overflow but rather than having a value of 3'147'483'647 it will have a value of -1'147'483'649.

    You can deal with this by checking if the return is negative and if so coerce it to a type such as Currency and then add 4'294'967'296 to it to get the value you want.
    Code:
      Dim myLong As Long, myCur As Currency
      myLong = APIFunctionThatReturnsUInt32()
      myCur = CCur(myLong)
      If myCur < 0 Then
         myCur = myCur + 4294967295@
      End If


    Ok i started my tread if you whant take a look
    http://www.vbforums.com/showthread.p...60#post4059160

    i think is important for us to still support vb6 if someoneelse (Mic...t) do not do.

    Thank

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.