How can I convert a color selected with SelectColor to a hex value in this format #ffffff?
Have you looked in the documentation for color? It’s there:
Color Values to/from Hex Strings
If you take a look here the code you want is just below the blue box:
Dim hexColor As String = Str(c)
or if you don’t want the Alpha value
Dim hexColor As String = Str(c).left(8)
I did try that but it gives the wrong result. When the color white is selected and I use the methods posted here, which are in the docs, I get the wrong result of &h 00FFFF
What OS ?
In that case you’ll need:
Dim hexColor As String = "#" + Str(c).right(6)
I’ve not played around with colour much, there’s bound to be some reason why the Alpha changes position and isn’t mentioned in the docs Not even a mention like “Oh by the way, if you make a colour from a hex string you’ll need &hAARRGGBB”, and then &c needs it in a different format, odd. I’m sure if someone knows they will let us know
That worked a treat, Julian. Thank you.
If you think about it, the hex format is based on the fact that RGB is 24 bits and occupies the low 3 bytes of a 32-bit integer, so the alpha channel has to be in the high byte. To maintain backward compatibility, the &c version has to add AA to the end, where it is optional, but &h has to add it to the front.
&cRRGGBB = &cRRGGBB00
&hRRGGBB = &h00RRGGBB