
hex-color's -----> vbcolors
Quote:
>Can anyone help me with a code for converting hexcolor's in vbcolors
>example :
>blanc -----> hex : #000000 -----> vb : &H00000000&
That's a silly example. It doesn't show how the RGB values are put
together. One thing I'm sure of: the first two hex digits are the "red",
and that's the lower byte in VB. Yup, the right side. I ASSUME that the
middle is Green for both (as in "RGB") and the Blue is at the opposite
end than the Red. A few testes comparing VB and a browser seem to
confirm that assumption.
In that case, all you need to do is shuffle the values:
dim hashRGB$, vbRGB$
hashRGB$ = "#80C040" 'example
vbRGB$ = "&H" & mid$(hashRGB$, 6, 2) & mid$(hashRGB$, 4, 2) _
& mid$(hashRGB$, 2, 2)
' vbRGB$ now is "&H40C080"
if you want to convert this to a vb long, try CLng(vbRGB$).
Careful: if the highest bit of the middle (G) value is set, and the
highest byte (B) is "00" (number between &H008000 and &H00FFFF), then VB
will incorrectly convert this as a signed integer, and THEN convert it
to Long, so "&H00C040" will be treated as &HC040 = &HFFFFC040&.
If you notice that you get a negative value, add &H10000 to that result.
Dim lRGB&
lRGB& = Clng(vbRGB$)
if lRGB<0 then lRGB = lRGB + &H10000
--
Bart.