|
-
Sep 7th, 2002, 03:09 PM
#1
Thread Starter
Frenzied Member
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.
-
Sep 7th, 2002, 03:43 PM
#2
The picture isn't missing
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
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Sep 7th, 2002, 04:01 PM
#3
Hyperactive Member
i have made a rgb to hex prog its very cool
-
Sep 7th, 2002, 04:02 PM
#4
The picture isn't missing
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  .
-
Sep 7th, 2002, 04:13 PM
#5
Thread Starter
Frenzied Member
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.
-
Sep 7th, 2002, 04:15 PM
#6
Thread Starter
Frenzied Member
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.
-
Sep 7th, 2002, 04:16 PM
#7
The picture isn't missing
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|