If you want to convert a colour expressed in hex to RGB() format try the following.
Depending on your needs and use, you may need to add additional error trapping to validate the string passed to the function Hex2RGB(), as the function assumes, apart from typos, that the hex string passed is a 'legal' Windows colour.
Thread184-658948 discusses a RGB2Hex() function, and FAQ184-4203 is a Bin - Dec - Hex - RGB Converter
[color blue]
lcRGB = Hex2RGB([#ff00ff])
? lcRGB
[color green]
****************[color blue]
FUNCTION Hex2RGB
LPARAMETERS Str2Convert
LOCAL i, lnPos
DO CASE
CASE SUBSTR(Str2Convert,1,1) # [#]
MESSAGEBOX([Invalid string])
Str2Return = [Error!]
CASE LEN(Str2Convert) # 7
MESSAGEBOX([Invalid string])
Str2Return = [Error!]
OTHE
Str2Return = [RGB(]
lnPos = 2
FOR i = 1 TO 3
lcValue = Hex2Dec(SUBSTR(Str2Convert,lnPos,2))
IF i # 3
Str2Return = Str2Return + lcValue + [,]
ELSE
Str2Return = Str2Return + lcValue + [)]
ENDI
lnPos = lnPos + 2
ENDF
ENDCASE
RETURN Str2Return
[color green]
****************[color blue]
FUNCTION Hex2Dec
LPARAMETERS HexString
LOCAL i, llcChar, lnLen, lnSum, lnPos
lnLen = LEN(HexString)
lnSum = 0
lnPos = 0
FOR i = 1 TO lnLen
lcChar = SUBSTR(HexString,lnLen-lnPos,1)
DO CASE
CASE UPPER(lcChar) = [A]
lcChar = [10]
CASE UPPER(lcChar) = "B"
lcChar = [11]
CASE UPPER(lcChar) = [C]
lcChar = [12]
CASE UPPER(lcChar) = [D]
lcChar = [13]
CASE UPPER(lcChar) = [E]
lcChar = [14]
CASE UPPER(lcChar) = [F]
lcChar = [15]
ENDCASE
lnSum = lnSum + VAL(UPPER(lcChar)) * 16^(i-1)
lnPos = lnPos + 1
ENDFOR
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.