INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Microsoft: Visual FoxPro FAQ

## Usefull Functions & Procedures

 How can I convert a hex colour to RGB() by ChrisRChamberlain faq184-4204 Posted: 21 Sep 03 (Edited 21 Sep 03) 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    lcRGB = Hex2RGB([#ff00ff])? lcRGB****************FUNCTION Hex2RGBLPARAMETERS Str2ConvertLOCAL i, lnPosDO CASECASE 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    ENDFENDCASERETURN Str2Return****************FUNCTION Hex2DecLPARAMETERS HexStringLOCAL i, llcChar, lnLen, lnSum, lnPoslnLen =    LEN(HexString)lnSum =    0lnPos =    0FOR 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 +    1ENDFORRETURN TRANSFORM(lnSum)Have fun! Back to Microsoft: Visual FoxPro FAQ Index Back to Microsoft: Visual FoxPro Forum

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!