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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can color components be returned

Status
Not open for further replies.

yaakov

Technical User
Oct 18, 2000
9
IL
Help please!!!I need to know how can i get the rgb components from backcolor or forecolor or other given color?Thanks


[sig][/sig]
 
What-ho,


Here's an example code snippet:

Get a form and put seven text boxes on it, called text1 to text7.

Now, put this into your form_load event:

Me.BackColor = RGB(170, 170, 255)
Me.Text1.Text = Hex(Me.BackColor)
Me.Text4.Text = Mid(Right(Me.Text1.Text, 2), 1, 2)
Me.Text3.Text = Mid(Right(Me.Text1.Text, 4), 1, 2)
Me.Text2.Text = IIf(Len(Mid(Right(Me.Text1.Text, 6), 1, 2)) < 2, _
&quot;0&quot; & Mid(Right(Me.Text1.Text, 6), 1, 2), _
Mid(Right(Me.Text1.Text, 6), 1, 2))
Me.Text5.Text = CStr(Val(&quot;&H&quot; & Text2.Text))
Me.Text6.Text = CStr(Val(&quot;&H&quot; & Text3.Text))
Me.Text7.Text = CStr(Val(&quot;&H&quot; & Text4.Text))

This sort of goes through thew whole process of first setting your form.backcolor using the RGB() function and then retrieving it, converting it from the long format the property returns as to hex, reliably splitting the long into three two byte hex values and then converting these into decimal values.

So there you have it, decimal to hex to decimal in only, erm, about a million easy steps...


Cheerio,

Paul

[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top