|
-
Jun 8th, 2025, 01:15 PM
#1
Thread Starter
New Member
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???
-
Jun 8th, 2025, 11:55 PM
#2
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
-
Jun 9th, 2025, 08:25 AM
#3
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.
-
Jun 9th, 2025, 08:59 AM
#4
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.
-
Jun 9th, 2025, 11:13 AM
#5
Fanatic Member
Re: VB6 Removes Trailing Ampersand at end of hexadecimal
 Originally Posted by TechnicDragon
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
-
Jun 9th, 2025, 11:14 AM
#6
Fanatic Member
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
-
Jun 9th, 2025, 11:35 AM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|