Results 1 to 7 of 7

Thread: VB6 Removes Trailing Ampersand at end of hexadecimal

  1. #1

    Thread Starter
    New Member TechnicDragon's Avatar
    Join Date
    Jul 2014
    Location
    Texas, USA
    Posts
    3

    Exclamation VB6 Removes Trailing Ampersand at end of hexadecimal

    Working in VB6.
    I will use a text editor for doing some typing work, but it's just text. When I think it's ready, I will paste the text over into the code.

    I copy and paste this...

    Code:
        color_Orange = clng(&HFFBF00&)
        color_Lime = clng(&HBFFF00&)
        color_Pink = clng(&HFF00BF&)
        color_Purple = clng(&HBF00FF&)
        color_Sky = clng(&HFFBF&)
        color_Blue = clng(&HBFFF&)
        color_DarkGray = clng(&H404040&)

    BUT, I get this...

    Code:
        color_Orange = CLng(&HFFBF00)
        color_Lime = CLng(&HBFFF00)
        color_Pink = CLng(&HFF00BF)
        color_Purple = CLng(&HBF00FF)
        color_Sky = CLng(&HFFBF)
        color_Blue = CLng(&HBFFF)
        color_DarkGray = CLng(&H404040)
    If I'm supposed to use trailing ampersands for color codes, why is VB6 removing them???

  2. #2
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,668

    Re: VB6 Removes Trailing Ampersand at end of hexadecimal

    I presume that you want to use these variables as constants.
    Code:
    Const color_Orange As Long = &HFFBF00&
    Const color_Lime As Long = &HBFFF00&
    Const color_Pink As Long = &HFF00BF&
    Const color_Purple As Long = &HBF00FF&
    Const color_Sky As Long = &HFFBF&
    Const color_Blue As Long = &HBFFF&
    Const color_DarkGray As Long = &H404040&
    When transferred to code, only color_Sky and color_Blue will retain the trailing ampersand. That is because those could be interpreted as integers. The rest only fit in longs.

    J.A. Coutts

  3. #3
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,909

    Re: VB6 Removes Trailing Ampersand at end of hexadecimal

    When dealing with hex literals (or even base-10 literals for that matter), the VB6 IDE Intellisense removes the trailing & from integer literals it already knows must be fit into a Long variable or constant. However, if the literal can be fit into an Integer or a Long, the & must be specified to force the literal to be a Long.

    For instance:

    Code:
    Const i As Long = &H77777777 ' If we put a terminating & on it, Intellisense will remove it because &H77777777 won't fit into an Integer.
    However:

    Code:
    Const i As Long = &H7777 ' The literal will just be an Integer, and the compiler will cast it into a Long when creating the constant.
    But:

    Code:
    Const i As Long = &H7777& ' Now, both the literal and the created constant will be Long types.
    However, the only time this really matters is when the sign-bit might be on in the literal. For instance:

    Code:
    Const i As Long = &H8444& ' This will create the i Long constant = &H00008444
    But:

    Code:
    Const i As Long = &H8444 ' This will create the i Long constant = &HFFFF8444 which probably isn't what you want.
    In the immediately above, the Integer literal's sign bit is extended into the Long constant's sign bit, using 2s complement logic.
    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.

  4. #4
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: VB6 Removes Trailing Ampersand at end of hexadecimal

    Building upon what Elroy said, this also means that the CLng function is unnecessary. You typically don't use that for constants anyway, hex or otherwise. VB will implicitly convert it based on the type of the variable being assigned to.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  5. #5
    Fanatic Member gaouser's Avatar
    Join Date
    Mar 2022
    Location
    Turkey, down the old sides of Fatih
    Posts
    607

    Re: VB6 Removes Trailing Ampersand at end of hexadecimal

    Quote Originally Posted by TechnicDragon View Post
    Working in VB6.
    I will use a text editor for doing some typing work, but it's just text. When I think it's ready, I will paste the text over into the code.

    I copy and paste this...

    Code:
        color_Orange = clng(&HFFBF00&)
        color_Lime = clng(&HBFFF00&)
        color_Pink = clng(&HFF00BF&)
        color_Purple = clng(&HBF00FF&)
        color_Sky = clng(&HFFBF&)
        color_Blue = clng(&HBFFF&)
        color_DarkGray = clng(&H404040&)

    BUT, I get this...

    Code:
        color_Orange = CLng(&HFFBF00)
        color_Lime = CLng(&HBFFF00)
        color_Pink = CLng(&HFF00BF)
        color_Purple = CLng(&HBF00FF)
        color_Sky = CLng(&HFFBF)
        color_Blue = CLng(&HBFFF)
        color_DarkGray = CLng(&H404040)
    If I'm supposed to use trailing ampersands for color codes, why is VB6 removing them???
    Elroy has explained it, but to be honest its pretty cosmeticish so just ignore it

    got nuthin' to do but to make a new project, hype, then give up

    Check out all my cool stuff btw
    VB: EveryDiscord, a Discord client made fully in VB6 | MSPaint Modifier, a VB6-based MSPaint hooking engine, experimental | OpenIM, a fully VB6 instant messaging service based on TCP/IP connections | Kadooki (Overall the AltWWW project), the WWW re-imagined by me with continuations of HTML3.2's parts. | ClaFeed, A little feed algorithm I have been developing for a Twitter-style system. | CfmOS PC, my project CfmOS ported to VB6 in order to prototype faster, often lags on updates though!

    C: LegacyResource, a little ResHacker ripoff | CfmOS, A mobile OS designed to mimic AOSP (Stock Android) on an ESP32-S3, featuring a full bytecode architecture

  6. #6
    Fanatic Member gaouser's Avatar
    Join Date
    Mar 2022
    Location
    Turkey, down the old sides of Fatih
    Posts
    607

    Re: VB6 Removes Trailing Ampersand at end of hexadecimal

    Code will fully work, a similar thing is vbWhite and vbBlacks values being trimmed.

    got nuthin' to do but to make a new project, hype, then give up

    Check out all my cool stuff btw
    VB: EveryDiscord, a Discord client made fully in VB6 | MSPaint Modifier, a VB6-based MSPaint hooking engine, experimental | OpenIM, a fully VB6 instant messaging service based on TCP/IP connections | Kadooki (Overall the AltWWW project), the WWW re-imagined by me with continuations of HTML3.2's parts. | ClaFeed, A little feed algorithm I have been developing for a Twitter-style system. | CfmOS PC, my project CfmOS ported to VB6 in order to prototype faster, often lags on updates though!

    C: LegacyResource, a little ResHacker ripoff | CfmOS, A mobile OS designed to mimic AOSP (Stock Android) on an ESP32-S3, featuring a full bytecode architecture

  7. #7
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,909

    Re: VB6 Removes Trailing Ampersand at end of hexadecimal

    Again, the only time there's any problem is when the sign bit (negation) is on, and you're assigning an Integer to a Long (or vice-versa). In either of these cases, the hex value of the Integer will not equal the hex value of the Long. This is true when creating constants with literals, and it's also true when just making regular assignments with variables.

    Basically, it takes an understanding of 2s complement to understand this. In my examples above, it may not seem like it, but, when thinking in base-10, the following are equal:

    &H8444 (as an Integer) = &HFFFF8444 (as a Long)

    Here's the proof:

    Code:
    Private Sub Form_Load()
        Debug.Print &H8444          ' Prints -31676
        Debug.Print &HFFFF8444      ' Prints -31676
    End Sub
    But, if we're strictly thinking in hex, it doesn't make sense until we realize how 2s complement casting from an Integer to a Long (or vice-versa) works, and that VB6 doesn't have unsigned integers ... so 2s complement is always there. (Well, I guess the Byte type is unsigned. Just saying that before someone corrects me.)
    Last edited by Elroy; Jun 9th, 2025 at 11:44 AM.
    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.

Tags for this Thread

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