Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vb color picker 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I require a working formula that allows me to translate a VB decimal color into an RGB color.
 
Hiya,

Glad to hear it.

I require a question please.

Regards,

Darrylle "Never argue with an idiot, he'll bring you down to his level - then beat you with experience."
 
Standard colors in VB are stored as Longs.

Each component (R, G & B) are stored internally as 2 byte parts (ie 0-255).

The whole color is stored as B*65535 + G*255 + R

Check out VB help on the RGB function

Let me know if this helps
 
Thank you for your input johnwm,
I asked for a formula that gives me an RGB from a decimal, you have given me a decimal from an RGB, furthermore this formula of yours makes no sense to me because if I have an RGB value of (255, 255, 255) then the decimal value should be 16 777 216, but according to your formula I get a decimal value of 16 776 705. I might be reading it wrong though could you please verify it for me.

Thank you.
Ochoruss
 
My apologies

"The whole color is stored as B*65535 + G*255 + R"
should read
"The whole color is stored as B*65536 + G*256 + R"

My answer was intended to put you on the right path, and I assumed that generating the reverse function is trivial.

Code:
Private Sub Command1_Click()
Dim a As Long
Dim r As Long
Dim g As Long
Dim b As Long
a = YourDecimal
r = a Mod 256
a = (a - r) / 256
g = a Mod 256
a = (a - g) / 256
b = a
MsgBox "r " & r & vbCrLf & "g " & g & vbCrLf & "b " & b & vbCrLf
End Sub

Let me know if this helps by giving a star!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top