hex-color's -----> vbcolors
Author Message
hex-color's -----> vbcolors

Can anyone help me with a code for converting hexcolor's  in vbcolors

example :

blanc -----> hex : #000000 -----> vb : &H00000000&

Thor

Mon, 08 Apr 2002 03:00:00 GMT
hex-color's -----> vbcolors

Me again,

...

Quote:
> Can anyone help me with a code for converting hexcolor's  in vbcolors

> example :

> blanc -----> hex : #000000 -----> vb : &H00000000&

> Thor

Mon, 08 Apr 2002 03:00:00 GMT
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.

Tue, 09 Apr 2002 03:00:00 GMT
hex-color's -----> vbcolors
Here is a simple example:

MsgBox "vbYellow = &H" & Right\$("0000000" & Hex\$(vbYellow),
8) & "&"

Just plug in vbRed, vbGreen, etc, in this example.

By the way, why do you need this?

Hope this helps.

-- David Martin

Quote:

>Can anyone help me with a code for converting hexcolor's  in vbcolors

>example :

>blanc -----> hex : #000000 -----> vb : &H00000000&

>Thor

Tue, 09 Apr 2002 03:00:00 GMT
hex-color's -----> vbcolors
Hello,

Here is a chart I made up a while ago that translates
QBCOLOR values into hex.  I don't know if this is really
what you want but maybe it will help.

0 - Black - 0
1 - Blue - 800000
2 - Green - 8000
3 - Cyan - 808000
4 - Red - 80
5 - Magenta - 800080
6 - Yellow - 8080
7- White - C0C0C0
8 - Gray - 808080
9 - Light Blue - FF0000
10 - L. Green - FF00
11 - L. Cyan - FFFF00
12 - L. Red - FF
13 - L. Magenta - FF00FF
14 - L. Yellow - FFFF
15 - Bright White - FFFFFF

--

"For God So Loved The World, That He Gave His
Only Begotten Son, That Whosoever Believeth
In Him Should Not Perish, But Have Everlasting
Life"John3:16  * http://pw2.netcom.com/~cbrtjr/wrdthing.html *

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.

Tue, 09 Apr 2002 03:00:00 GMT
hex-color's -----> vbcolors
I'm not sure what you're asking for - doesn't the VB RGB() function do that?
RGB(red, green, blue)
If you want the value in hex, use Hex\$()
MyHexColor = Hex\$(RGB(&HC0,&H34,&HFF))

RobS
--

Me again,

...

Quote:
> Can anyone help me with a code for converting hexcolor's  in vbcolors

> example :

> blanc -----> hex : #000000 -----> vb : &H00000000&

> Thor

Tue, 09 Apr 2002 03:00:00 GMT
hex-color's -----> vbcolors
i believe its going to be &H00BBGGRR& for a palette color (white, black,
blue, etc.), and &H80BBGGRR& for System colors (active window, button,
tooltip, etc.)

trippz

Quote:
> Can anyone help me with a code for converting hexcolor's  in vbcolors

> example :

> blanc -----> hex : #000000 -----> vb : &H00000000&