?
Solved

change hex color to ligher or darker

Posted on 2004-10-11
2
Medium Priority
?
626 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
dfu23 earned 750 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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 would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

743 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