Results 1 to 4 of 4

Thread: Html Hex to RGB

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    364

    Html Hex to RGB

    hi,
    I have done a search but couldnt really find what i was looking for.
    I have 3 horizontal scroll bars, which are R G B, you can make different colours with this and it will give you the html hex code for the colour, how can i make it so it can convert html hex to rgb, and set the scrool bars to the correct value ?
    please help
    thanks
    Richard <><

  2. #2
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    use mid to break up the HTML hex string and use val to convert the 2-nibble hex vals to decimal for the scroll bars. When using val, you need to put &H in front of the 2-nibble hex, so if you have
    8a, it needs to become val(&H8a)

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    364
    um, can anyone help me a little more ?
    Richard <><

  4. #4
    New Member
    Join Date
    Oct 2002
    Posts
    4

    Hope this will work

    Public Function HEX2RGB(HexColorStr As String) As Long

    RED_COLOR = CLng("&H" & Mid(HexColorStr, 1, 2)) '(CLng("&H" & HexColorStr) And &HFF0000) / &HFFFF
    'mask 111111110000000000000000 and shift bits right

    GREEN_COLOR = CLng("&H" & Mid(HexColorStr, 3, 2)) '(CLng("&H" & HexColorStr) And &HFF00) / &HFF
    'mask 000000001111111100000000 and shift bits right

    BLUE_COLOR = CLng("&H" & Mid(HexColorStr, 5, 2)) 'CLng("&H" & HexColorStr) And &HFF
    'mask 000000000000000011111111 and shift bits right

    HEX2RGB = RGB(RED_COLOR, GREEN_COLOR, BLUE_COLOR)

    End Function

    usage : HEX2RGB("C0FABC")

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width