Solved

change hex color to ligher or darker

Posted on 2004-10-11
2
602 Views
Last Modified: 2010-05-18
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
------------------------

Thanks in advanced.
0
Comment
Question by:MadDog986
2 Comments
 
LVL 14

Accepted Solution

by:
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

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Microsoft VBScript compilation error '800a0401'  Expected end of statement 15 52
API not working 33 55
Forcing form refresh - classic ASP 7 57
is this a cms? 8 34
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now