Results 1 to 7 of 7

Thread: HEX to RGB Very exciting, please look ;)

  1. #1

    Thread Starter
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994

    Exclamation HEX to RGB Very exciting, please look ;)

    Does anybody have a function that converts HEX(HTML colors) to RGB(Red, Green, Blue). I would be very happy if you would post such a function

    Regards
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  2. #2
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    VB Code:
    1. Private Sub Form_Load()
    2.     Dim a As Byte, b As Byte, c As Byte
    3.     ToRGB "#FFFFFF", a, b, c
    4.     MsgBox a
    5.     MsgBox b
    6.     MsgBox c
    7. End Sub
    8.  
    9. Private Sub ToRGB(ByVal sHex As String, ByRef bR As Byte, ByRef bG As Byte, ByRef bB As Byte)
    10.     Dim sR As String
    11.     Dim sG As String
    12.     Dim sB As String
    13.     Dim sR1 As String
    14.     Dim sR2 As String
    15.     Dim sG1 As String
    16.     Dim sG2 As String
    17.     Dim sB1 As String
    18.     Dim sB2 As String
    19.  
    20.     sHex = UCase(sHex)
    21.     If Left(sHex, 1) = "#" And Len(sHex) = 7 Then
    22.         sR = Mid(sHex, 2, 2)
    23.         sG = Mid(sHex, 4, 2)
    24.         sB = Mid(sHex, 6, 2)
    25.     ElseIf Len(sHex) = 6 Then
    26.         sR = Mid(sHex, 1, 2)
    27.         sG = Mid(sHex, 3, 2)
    28.         sB = Mid(sHex, 5, 2)
    29.     End If
    30.    
    31.     sR1 = Chr(Asc(Left(sR, 1)))
    32.     sR2 = Chr(Asc(Right(sR, 1)))
    33.     sG1 = Chr(Asc(Left(sG, 1)))
    34.     sG2 = Chr(Asc(Right(sG, 1)))
    35.     sB1 = Chr(Asc(Left(sB, 1)))
    36.     sB2 = Chr(Asc(Right(sB, 1)))
    37.     'RED
    38.     If IsNum(sR1) Then
    39.         bR = (Asc(sR1) - 48) * 16
    40.     Else
    41.         bR = (Asc(sR1) - 55) * 16
    42.     End If
    43.     If IsNum(sR2) Then
    44.         bR = bR + (Asc(sR2) - 48)
    45.     Else
    46.         bR = bR + (Asc(sR2) - 55)
    47.     End If
    48.     'GREEN
    49.     If IsNum(sG1) Then
    50.         bG = (Asc(sG1) - 48) * 16
    51.     Else
    52.         bG = (Asc(sG1) - 55) * 16
    53.     End If
    54.     If IsNum(sG2) Then
    55.         bG = bG + (Asc(sG2) - 48)
    56.     Else
    57.         bG = bG + (Asc(sG2) - 55)
    58.     End If
    59.     'BLUE
    60.     If IsNum(sB1) Then
    61.         bB = (Asc(sB1) - 48) * 16
    62.     Else
    63.         bB = (Asc(sB1) - 55) * 16
    64.     End If
    65.     If IsNum(sB2) Then
    66.         bB = bB + (Asc(sB2) - 48)
    67.     Else
    68.         bB = bB + (Asc(sB2) - 55)
    69.     End If
    70. End Sub
    71.  
    72. Private Function IsNum(sNum As String) As Boolean
    73.     If Len(sNum) <> 1 Then
    74.         IsNum = False
    75.     ElseIf Asc(sNum) >= 48 And Asc(sNum) <= 57 Then
    76.         IsNum = True
    77.     End If
    78. End Function

    got it from here: http://maya.effectonline.com/~vbforu...light=html+rgb
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  3. #3
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    364
    i have made a rgb to hex prog its very cool
    Richard <><

  4. #4
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    uhh.... rgb to hex:

    color = hex(rgb(255,0,0))
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  5. #5

    Thread Starter
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994

    hmm

    Buggy, could you make a sample program that converts, ´
    RGB(255, 255, 255) to Hex=FFFFFF ??
    I would be very happy if you could, not sure how to use what you have postet
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  6. #6

    Thread Starter
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994

    Forget it :)

    Forget what i just posted, got it working now
    Thanks !
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  7. #7
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    if you wanted the reverse (rgb to html) then don't use the code i just gave you because it's reversed in html.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

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