469,636 Members | 1,527 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,636 developers. It's quick & easy.

How to convert to color?

How do I convert the following to a HEX code I can use in HTML documents?

1. [A=255, R=0, G=0, B=192]
2. Aqua

FYI: When I print the session variable I'm storing this color in (in the
Immediate window) I get this:
? session("MyBackgroundColor")
"Color [A=255, R=0, G=0, B=192]" {String}
String: "Color [A=255, R=0, G=0, B=192]"

Thanks!
Jan 3 '06 #1
5 1456
I don't think that there is a method to do that in the Color class. However,
if you plan on needing to do this more than a couple times I would simply
write your own function to do it. It wouldn't be hard, if you would like
help writing this function let me know. Good Luck!
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"VB Programmer" <do**@emailme.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
How do I convert the following to a HEX code I can use in HTML documents?

1. [A=255, R=0, G=0, B=192]
2. Aqua

FYI: When I print the session variable I'm storing this color in (in the
Immediate window) I get this:
? session("MyBackgroundColor")
"Color [A=255, R=0, G=0, B=192]" {String}
String: "Color [A=255, R=0, G=0, B=192]"

Thanks!

Jan 3 '06 #2
Hi VB Programmer,

First, you won't be able to use Alpha in an HTML document, so forget about
that part. As for creating a hexadecimal number from an RGB value, here's a
method I created that does this:

public static string ColorToHex(int R, int G, int B)
{
string r, g, b;
r = R.ToString("X2");
g = G.ToString("X2");
b = B.ToString("X2");
return "#" + r + g + b;
}

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"VB Programmer" <do**@emailme.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
How do I convert the following to a HEX code I can use in HTML documents?

1. [A=255, R=0, G=0, B=192]
2. Aqua

FYI: When I print the session variable I'm storing this color in (in the
Immediate window) I get this:
? session("MyBackgroundColor")
"Color [A=255, R=0, G=0, B=192]" {String}
String: "Color [A=255, R=0, G=0, B=192]"

Thanks!

Jan 3 '06 #3
Thanks everyone! You all rock!

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:et**************@TK2MSFTNGP14.phx.gbl...
Hi VB Programmer,

First, you won't be able to use Alpha in an HTML document, so forget about
that part. As for creating a hexadecimal number from an RGB value, here's
a method I created that does this:

public static string ColorToHex(int R, int G, int B)
{
string r, g, b;
r = R.ToString("X2");
g = G.ToString("X2");
b = B.ToString("X2");
return "#" + r + g + b;
}

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"VB Programmer" <do**@emailme.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
How do I convert the following to a HEX code I can use in HTML documents?

1. [A=255, R=0, G=0, B=192]
2. Aqua

FYI: When I print the session variable I'm storing this color in (in the
Immediate window) I get this:
? session("MyBackgroundColor")
"Color [A=255, R=0, G=0, B=192]" {String}
String: "Color [A=255, R=0, G=0, B=192]"

Thanks!


Jan 3 '06 #4
Hi VB Programmer,

Sorry, I just realized I gave you the code in C#. It sounds like you aren't
having any problems translating, but just in case:

Public Shared Function ColorToHex(ByVal R As Integer, _
ByVal G As Integer, ByVal B As Integer) As String
Dim red, blue, green As String
red = R.ToString("X2")
green = G.ToString("X2")
blue = B.ToString("X2")
Return "#" & red & green & blue
End Function

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"VB Programmer" <do**@emailme.com> wrote in message
news:ue**************@tk2msftngp13.phx.gbl...
Thanks everyone! You all rock!

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:et**************@TK2MSFTNGP14.phx.gbl...
Hi VB Programmer,

First, you won't be able to use Alpha in an HTML document, so forget
about that part. As for creating a hexadecimal number from an RGB value,
here's a method I created that does this:

public static string ColorToHex(int R, int G, int B)
{
string r, g, b;
r = R.ToString("X2");
g = G.ToString("X2");
b = B.ToString("X2");
return "#" + r + g + b;
}

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"VB Programmer" <do**@emailme.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
How do I convert the following to a HEX code I can use in HTML
documents?

1. [A=255, R=0, G=0, B=192]
2. Aqua

FYI: When I print the session variable I'm storing this color in (in
the Immediate window) I get this:
? session("MyBackgroundColor")
"Color [A=255, R=0, G=0, B=192]" {String}
String: "Color [A=255, R=0, G=0, B=192]"

Thanks!



Jan 3 '06 #5
Helpful as usual Kevin! Thanks.
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:eK**************@TK2MSFTNGP09.phx.gbl...
Hi VB Programmer,

Sorry, I just realized I gave you the code in C#. It sounds like you
aren't having any problems translating, but just in case:

Public Shared Function ColorToHex(ByVal R As Integer, _
ByVal G As Integer, ByVal B As Integer) As String
Dim red, blue, green As String
red = R.ToString("X2")
green = G.ToString("X2")
blue = B.ToString("X2")
Return "#" & red & green & blue
End Function

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"VB Programmer" <do**@emailme.com> wrote in message
news:ue**************@tk2msftngp13.phx.gbl...
Thanks everyone! You all rock!

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:et**************@TK2MSFTNGP14.phx.gbl...
Hi VB Programmer,

First, you won't be able to use Alpha in an HTML document, so forget
about that part. As for creating a hexadecimal number from an RGB value,
here's a method I created that does this:

public static string ColorToHex(int R, int G, int B)
{
string r, g, b;
r = R.ToString("X2");
g = G.ToString("X2");
b = B.ToString("X2");
return "#" + r + g + b;
}

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"VB Programmer" <do**@emailme.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
How do I convert the following to a HEX code I can use in HTML
documents?

1. [A=255, R=0, G=0, B=192]
2. Aqua

FYI: When I print the session variable I'm storing this color in (in
the Immediate window) I get this:
? session("MyBackgroundColor")
"Color [A=255, R=0, G=0, B=192]" {String}
String: "Color [A=255, R=0, G=0, B=192]"

Thanks!



Jan 4 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

19 posts views Thread by Lauren Quantrell | last post: by
2 posts views Thread by Joel Moore | last post: by
3 posts views Thread by Convert TextBox.Text to Int32 Problem | last post: by
7 posts views Thread by MilanB | last post: by
7 posts views Thread by patang | last post: by
6 posts views Thread by patang | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.