Click here to Skip to main content
15,917,174 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am converting hex color value into color name.

While converting, I am facing the error like this "ffffff80 is not a valid value for Int32."

Below is my code

VB
Dim xCol As String = clspfjbs02.colrnameobj
                   Dim k As Color
                   k = System.Drawing.ColorTranslator.FromHtml(xCol)
Posted
Updated 20-Nov-10 9:01am
v2
Comments
Dalek Dave 20-Nov-10 15:01pm    
Edited for Grammar.

When you read it from clspfjbs02.colrnameobj I assume it is returning a hex value "ffffff80"? If so, then just tack a '#' character in front of it :
VB
Dim xCol As String = "#" & clspfjbs02.colrnameobj
Dim k As Color
k = System.Drawing.ColorTranslator.FromHtml(xCol)
 
Share this answer
 
Comments
Dalek Dave 20-Nov-10 15:01pm    
Good Call.
sameertm 21-Nov-10 6:29am    
thnks its wrks cool
What you have is the hex representation of number, what the function wants is the actual number.

I so what you need to do is convert the hex string to a number first:

Dim xCol As Int32
Dim k As Color
xCol = Int32.Parse(clspfjbs02.colrnameob, HexNumber)
k = System.Drawing.ColorTranslator.FromHtml(xCol)
 
Share this answer
 
Try:
VB
k = System.Drawing.ColorTranslator.FromWin32(Integer.Parse("ffffff80", System.Globalization.NumberStyles.HexNumber))

:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900