Solved

# Color to fade from bright red to dark red with RGB-function

Posted on 2003-10-26
428 Views
Hi,
I think this a quite easy question for an expert, but I do not manage it:
In a database I have a field where items are in that are awaited for a certain date. If the items are not back by that date the row is paint in red. Now I want that the color is not only red but a certain tone of red depending on the days the item is not in time for ex. the item is in delay for 100 days, the row is dark red, for 50 days a lighter red and so on. I tried with: brush.color:= RGB(255,0,0) and that's OK only with red. How must I insert the RGB-values to have different shades of red ?
0
Question by:SCHUCla74
• 2

LVL 8

Expert Comment

255 is full brightness, 0 is nil. So use a value in between 0 and 255 for varying degrees of brightness. If you only use the first value, that is the red. Use a calculation to get degrees of redness for number of days.

Example:
if (DaysLate <= 0) then begin
Brush.Color := clWhite;
end else if (DaysLate <= 100) then begin
Brush.Color := RGB(Round(((100-DaysLate)/100) * 255), 0, 0);
end else begin
Brush.Color := clBlack;
end;

Which gives a white background if DaysLate is zero or less, varying degrees of red to black for 1 - 100 days late, and black for over 100 days late. Alter to suit your requirements.

Geoff M.
0

LVL 8

Accepted Solution

gmayo earned 100 total points
Actually, maybe you mean white to red. In which case that should be:
if (DaysLate <= 0) then begin
Brush.Color := clWhite;
end else if (DaysLate <= 100) then begin
v := Round(((100-DaysLate)/100) * 255);
Brush.Color := RGB(255, v, v);
end else begin
Brush.Color := clRed;
end;

Geoff M.
0

## Featured Post

### Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…