ASP 101 - Active Server Pages 101 - Web05
The Place ASP Developers Go!

Please visit our partners


Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash



 Top ASP 101 Stories Top ASP 101 Stories
An Overview of ASP.NET
Connections, Commands, And Procedures
What is ASP?

QUICK TIP:
Use RecordSet.Filter
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates


Quick Tips


Convert Colors Between RGB and Hex

In HTML colors are specified by indicating the three color components that make up the color desired. These are Red, Green, and Blue and are specified using their hexadecimal values from 0 (00) to 255 (FF). Color attributes follow this general form:

color="#RRGGBB"

where RR is the red component, GG is the green component, and BB is the blue component of the specified color. VBScript comes with the built in Hex function to convert decimal values to this hexadecimal form. For example:

<%= Hex(255) %>

will return FF which you could then use as any of the color components of an HTML color attribute. But what if you need to convert from the hexadecimal values to the standard decimal ones used by so many paint and drawing programs? There's really no function to do it built into VBScript.

The reason there's no function for it is that you really don't need one. Hexadecimal numbers are represented as numbers prefixed by "&H" and if you ask VBScript to give you their value, it'll automatically convert them to decimal form. For example:

<%= &HFF %>

will return 255 without you doing anything at all. The real problem arises when you read that value in from somewhere. Most values that contain alphanumeric characters will come into VBScript as variants of sub-type string. Luckily it's solved easily enough. Simply pre-pend the "&H" I mentioned earlier and then convert to a numeric type and VBScript will figure everything out for you. While:

<%= "&H" & "FF" %>

returns &HFF

<%= CInt("&H" & "FF") %>

will return the 255 we're looking for.


Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to: webmaster@asp101.com.


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers