Return to Snippet

Revision: 12399
at March 12, 2009 17:28 by blackf0rk


Initial Code
Public Function GiveDec(Hex)
  if Hex = "A" then
    Value = 10
  elseif Hex = "B" then
    Value = 11
  elseif Hex = "C" then
    Value = 12
  elseif Hex = "D" then
    Value = 13
  elseif Hex = "E" then
    Value = 14
  elseif Hex = "F" then
    Value = 15
  else
    Value = Hex
  end if
  GiveDec = Value
End Function

Public Function HexToDec(Hex)
  Dim a,b,c,d,e,f,x,y,z,fHex
  fHex = Replace(Hex,"#","")

  a = Left(fHex,1)
  a = GiveDec(a)
  b = Mid(fHex,2,1)
  b = GiveDec(b)
  c = Mid(fHex,3,1)
  c = GiveDec(c)
  d = Mid(fHex,4,1)
  d = GiveDec(d)
  e = Mid(fHex,5,1)
  e = GiveDec(e)
  f = Right(fHex,1)
  f = GiveDec(f)

  x = (a * 16) + b
  y = (c * 16) + d
  z = (e * 16) + f

  HexToDec = """" & x & "," & y & "," & z & """"
End Function

Initial URL
http://codefinds.blogspot.com/2007/10/hex-to-dec-vbscript.html

Initial Description
Convert hexidecimal color codes (ie #C0C0C0) to decimal RGB (ie 255,255,255)

Initial Title
Hex to Dec (RGB)

Initial Tags
color

Initial Language
VB.NET