How to convert to color?

V

VB Programmer

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!
 
N

Nathan Sokalski

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!
 
K

Kevin Spencer

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.
 
V

VB Programmer

Thanks everyone! You all rock!

Kevin Spencer said:
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 said:
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!
 
K

Kevin Spencer

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 said:
Thanks everyone! You all rock!

Kevin Spencer said:
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 said:
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!
 
V

VB Programmer

Helpful as usual Kevin! Thanks.


Kevin Spencer said:
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 said:
Thanks everyone! You all rock!

Kevin Spencer said:
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.

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top