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
Printable View
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
VB Code:
Private Sub Form_Load() Dim a As Byte, b As Byte, c As Byte ToRGB "#FFFFFF", a, b, c MsgBox a MsgBox b MsgBox c End Sub Private Sub ToRGB(ByVal sHex As String, ByRef bR As Byte, ByRef bG As Byte, ByRef bB As Byte) Dim sR As String Dim sG As String Dim sB As String Dim sR1 As String Dim sR2 As String Dim sG1 As String Dim sG2 As String Dim sB1 As String Dim sB2 As String sHex = UCase(sHex) If Left(sHex, 1) = "#" And Len(sHex) = 7 Then sR = Mid(sHex, 2, 2) sG = Mid(sHex, 4, 2) sB = Mid(sHex, 6, 2) ElseIf Len(sHex) = 6 Then sR = Mid(sHex, 1, 2) sG = Mid(sHex, 3, 2) sB = Mid(sHex, 5, 2) End If sR1 = Chr(Asc(Left(sR, 1))) sR2 = Chr(Asc(Right(sR, 1))) sG1 = Chr(Asc(Left(sG, 1))) sG2 = Chr(Asc(Right(sG, 1))) sB1 = Chr(Asc(Left(sB, 1))) sB2 = Chr(Asc(Right(sB, 1))) 'RED If IsNum(sR1) Then bR = (Asc(sR1) - 48) * 16 Else bR = (Asc(sR1) - 55) * 16 End If If IsNum(sR2) Then bR = bR + (Asc(sR2) - 48) Else bR = bR + (Asc(sR2) - 55) End If 'GREEN If IsNum(sG1) Then bG = (Asc(sG1) - 48) * 16 Else bG = (Asc(sG1) - 55) * 16 End If If IsNum(sG2) Then bG = bG + (Asc(sG2) - 48) Else bG = bG + (Asc(sG2) - 55) End If 'BLUE If IsNum(sB1) Then bB = (Asc(sB1) - 48) * 16 Else bB = (Asc(sB1) - 55) * 16 End If If IsNum(sB2) Then bB = bB + (Asc(sB2) - 48) Else bB = bB + (Asc(sB2) - 55) End If End Sub Private Function IsNum(sNum As String) As Boolean If Len(sNum) <> 1 Then IsNum = False ElseIf Asc(sNum) >= 48 And Asc(sNum) <= 57 Then IsNum = True End If End Function
got it from here: http://maya.effectonline.com/~vbforu...light=html+rgb
i have made a rgb to hex prog its very cool
uhh.... rgb to hex:
color = hex(rgb(255,0,0))
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 :rolleyes:
Forget what i just posted, got it working now :)
Thanks !
if you wanted the reverse (rgb to html) then don't use the code i just gave you because it's reversed in html.