Changing Luminosity of report controls programmatically

J

JB

Hello. I have an MS Access project where I have to programatically change
the background color of controls on a report. What I need to do on the
report is have the background of the header print in a particular color which
I will know up front. Then, on say the first group I need to change the
background color to a percent of the header background color (say 90%) and
then on a second group, I need to change the color again to be say 50% of the
header color and then one more time on another section to be say 30% of the
header color. So, I think I need to change the luminosity value in order to
generate a new hex number for this gradual 100%, 90%, 50%, 30% slide, but I
do not want to hard code this or figure these values out ahead of time and
store them. I want to be able to caculate these on the fly in the report. I
just want different shades of the header color for the different sections,
but do not know how to do this calculation on the fly. Thanks very much for
any help.

John
 
B

Bill

John
Color hues can be calculated by controlling the mix
amongst the 3 segments of the mix. I've not done
exactly what it is that you are trying to do, but if you
use any of the color properties to gain access to
"custom" colors, you can observe the values of the
three segments as you change the hue with the slide
bar.

Stephen Lebans might be the best source of "expert"
knowledge on the subject. Visit his site to see if there's
any help along the lines you're looking for:
www.lebans.com

Bill
 
J

jb

Hi Bill,

Yeah, I tried his site first and I didn't want to e-mail him directly as I
know he's probably busy enough as it is. I didn't see anything that
addressed this directly. I appreciate your suggestion and I'll play around
with some hexadecimal calculations as I think that is all that is required.
If I really have to, I can add some fields to a table and manually calculate
each shade and then store the values here. I was trying to avoid this.

Thanks again,

John
 
B

Bill

John,
If you come up with a calculation scheme, I'm sure it would be
well worth posting your findings.
Bill
 
S

Stephen Lebans

Actually I am currently on vacation for the rest of the summer and building
a home as well...very little time for programming.
If I understand your request you simply want to:
Seperate the Long RGB color value into its constituent RGB values.
Derive a modified RGB value by multiplying the individual RGB components by
a fixed percentage.
Combine the RGB components back into a Long RGB value.


' This sample code requires 3 Label controls named lblBlue, lblGreen and
lblRed. Obviously you will have to modify as required.

Declare Sub RtlMoveMemory Lib "kernel32" (dest As Any, src As Any, ByVal
Length As Long)

Private Sub cmdCOlor_Click()
Dim ColorBytes(3) As Byte
Dim ColorLong As Long


ColorLong = PutYourLongColorValueHere


RtlMoveMemory ColorBytes(0), ColorLong, 4
lblBlue.Caption = "Blue: " & ColorBytes(2)
lblGreen.Caption = "Green: " & ColorBytes(1)
lblRed.Caption = "Red: " & ColorBytes(0)


End Sub


After you calculate the new RGB values you can recombine them using the VBA
RGB method.
Me.NameOfMyControl.BackColor = RGB(ColorBytes(0),ColorBytes(1),ColorBytes(2)

You will need to add error checking, specifically boundary logic to see if
the calculated R,G, or B value exceeds 255 or is less than zero, which are
the limits of a BYTE value.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
J

jb

So much for vacation! I appreciate your response and yes, that is what I am
trying to do, vary the RGB value by a fixed %. Will play around with this
as I am not familiar with the RGB function, but I understand the pseudocode.
Thanks again!!!

John
 
J

jb

I tweaked it into a function and it works great! Thanks for the help.

Funny you should mention building your own home as this function was needed
for a homebuilder that I wrote a Selections System for in Access (people buy
an unfurnished model and then sit in front of my system and make selections
for flooring, lighting, appliances, etc. which builds the whole shopping
cart experience and then freaks them out with the final "extras" number -
I'm sure you are there or getting there yourself!)

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top