|
-
May 27th, 2000, 09:10 AM
#1
How would I convert something like &HFFFFFF into RGB(255, 255, 255)?
-
May 27th, 2000, 09:28 AM
#2
PowerPoster
Use Cdec function
Dreamlax, may be you can use the CDec function as below:
Code:
Private Sub Form_Load()
Dim R%, G%, B%
Dim HexColorCode$
HexColorCode = "&HFFFFFF"
'Assume Hex Color Code = &HFFFFFF
R = CDec("&H" & Mid(HexColorCode, 3, 2))
G = CDec("&H" & Mid(HexColorCode, 5, 2))
B = CDec("&H" & Mid(HexColorCode, 7, 2))
MsgBox "&HFFFFFF = RGB(" & R & ", " & G & ", " & B & ")"
End Sub
-
May 27th, 2000, 09:42 AM
#3
That won't work if the colour is black because black is &H0 not &H000000.
-
May 27th, 2000, 10:01 AM
#4
it would be pretty complicated...
but the concept of hex is easy
I am only posting for the blue, because it takes along time to type it up, and takes up too much space, but you can gain the general concept by this table....
http://denniswrenn.virtualave.net/RGBHEX.htm
[Edited by denniswrenn on 05-27-2000 at 11:13 PM]
-
May 27th, 2000, 10:11 AM
#5
PowerPoster
New GetRGB Function
Hi Dreamlax, This more flexible & resolve your problem,
Code:
Option Explicit
Private Sub Form_Load()
Dim R%, G%, B%
Dim HexColorCode$
'Assume Hex Color Code = &HFFFFFF
HexColorCode = "&H0"
R = GetRGB(CDec(HexColorCode), 1)
G = GetRGB(CDec(HexColorCode), 2)
B = GetRGB(CDec(HexColorCode), 3)
MsgBox HexColorCode & " = RGB(" & R & ", " & G & ", " & B & ")"
End Sub
Function GetRGB(RGBval As Long, Num As Integer) As Integer
' RGB color value as Long, and component number as integer
' that represents the component color to return (1=red,
' 2=green, 3=blue).
' Check if Num, RGBval are valid.
If Num > 0 And Num < 4 And RGBval > -1 And RGBval < 16777216 Then
GetRGB = RGBval \ 256 ^ (Num - 1) And 255
Else
' Return True (-1) if Num or RGBval are invalid.
GetRGB = 0
End If
End Function
-
May 27th, 2000, 06:50 PM
#6
transcendental analytic
Just don't get upset but making all the fancy rgb functions
will just drain your performance. The fastest way is always
is the straightest
Code:
R=color mod 256
G=int(color/256) mod 256
B=int(color/&H10000)
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
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
|