Solved

# change hex color to ligher or darker

Posted on 2004-10-11
599 Views
I need some kind of function that can i change a hex color to lighter or darker.

Example:
------------------------

strColor = LightenColor("#000000", 50)
strColor2 = LightenColor("#FFFFFF", 25)

Function LightenColor(strHex, strValue)
'strHex holds the color
'strValue holds how much to change
'Code to lighten color
End Function

Function DarkenColor(strHex, strValue)
'strHex holds the color
'strValue holds how much to change
'Code to lighten color
End Function
------------------------

0

LVL 14

Accepted Solution

dfu23 earned 250 total points
ID: 12280930
Something along these lines ... intPercentage can be a positive number to lighten and negative to darken:

Function LightenDarken(intR, intG, intB, intPercent)
Dim r : r = Int((intR * intPercent) / 100)
Dim g : g = Int((intG * intPercent) / 100)
Dim b : b = Int((intB * intPercent) / 100)
If r > 255 Then r = 255
If g > 255 Then g = 255
If b > 255 Then b = 255
If r < 0 Then r = 0
If g < 0 Then g = 0
If b < 0 Then b = 0
r = Hex(r)
g = Hex(g)
b = Hex(b)
If Len(r) = 1 Then r = "0" + r
If Len(g) = 1 Then g = "0" + g
If Len(b) = 1 Then b = "0" + b
LightenDarken = r + g + b
End Function
0

Author Comment

ID: 12295439
thanks, had to edit it a bit but that works.
0

## Featured Post

### Suggested Solutions

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interactâ€¦
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/â€¦
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

#### Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!