Solved Adjust Luminosity via VBA of any color value to it's lightest shade (1 Viewer)

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 06:02
Joined
Feb 28, 2001
Messages
27,001

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 11:02
Joined
Sep 12, 2006
Messages
15,614

Hmm. I sort of get the impression that HSL IS "the same" as RGB - ie - you get there in a different way, but you end up with the same decimal representation under both mechanisms.


[edit - What I originally meant was "do you still get to the same decimal colour number" - ie do the values of RGB component always correspond to a particular HSL value, and I am sure they do. However, there must be an extra hidden (negative?) component to derive the HSL values, since eg, Black Hex000000 is HSL 160,0,0, and white is HSL 160,0,240. I note that 160 and 240 are both multiples of 16.

[edit - incidentally, the links on the URL you posted weren't working, but I just realised I could watch the embedded video, and that actually helped a lot, seeing how one colour was on the same "horizontal" row as another, while the other colour was on the same "vertical" column, so that each colour was "identical" to the other, within the individual palette. (which is probably confusing terminologies - I will consult wiki when I get a moment!)
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 11:02
Joined
Jan 14, 2017
Messages
18,186
Still not clear what the V is in HSV.
 

Mike Krailo

Well-known member
Local time
Today, 07:02
Joined
Mar 28, 2020
Messages
1,030
That was an eye opening explanation on how to harmonize colors Doc_Man.
 

Mike Krailo

Well-known member
Local time
Today, 07:02
Joined
Mar 28, 2020
Messages
1,030
Still not clear what the V is in HSV.
H is Hue, S is Saturation, and V is the Value of Brightness. Why they didn't pick B or L? I have no idea, but it's essentially the same key thing that I would like to manipulate keeping the value for H & S constant.

For now, I'm going back to using a table of values to link to and do it that way. The issue now is I cannot import the csv file of color pallets. I keep getting the following error.

1616986885057.png
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 11:02
Joined
Sep 12, 2006
Messages
15,614
H is Hue, S is Saturation, and V is the Value of Brightness. Why they didn't pick B or L? I have no idea, but it's essentially the same key thing that I would like to manipulate keeping the value for H & S constant.

For now, I'm going back to using a table of values to link to and do it that way. The issue now is I cannot import the csv file of color pallets. I keep getting the following error.

View attachment 90371

On the link that @The_Doc_Man posted it says HSL and HSB are the same L=Luminosity, and B=Brightness. Your V is the same. I imagine it's specifically not B for colour handling, because we already have B in RGB, and you don't want another B (in the same way as n is minutes in date formats)
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 06:02
Joined
Feb 28, 2001
Messages
27,001
CMYK is specifically used for printing because colors on a video screen are additive but colors of ink are subtractive.

Red + Green on video = Yellow

Cyan + Yellow on print = Green
 

Mike Krailo

Well-known member
Local time
Today, 07:02
Joined
Mar 28, 2020
Messages
1,030
OK, I have a few formula's now that seem to be working when I step through the code but I'm not used to working with Type's so I'm a little confused how these are used or how to get the values after running the functions. I getting the Oops messages again when trying to post code so instead I just have it in a text file. What a pain.
 

Attachments

  • ColorFormulas.zip
    1.4 KB · Views: 183

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:02
Joined
May 7, 2009
Messages
19,175
you declare a variable As ColorProperties/Variant
then you call RGBtoHSL with your RGB value, it will be converted to HSL.

dim varHSL As Variant
varSHL = RGBtoHSL(theLongRGBValue)

if it is in Hex:

varSHL = RGBtoHSL(HexToDec(theHexString))


Note that you cannot call HSLtoRGB() function when your local ColorProperties has
no value as you will have division by zero error there.


Edit: add error handler.
 

Mike Krailo

Well-known member
Local time
Today, 07:02
Joined
Mar 28, 2020
Messages
1,030
Arnelgp, I did that and now I have a variable varHSL, but there is nothing in it! That's what I don't understand. If I do something like this it just gives me 0, 0, 0. Nevermind, I used the wrong elements in the code. I was expecting all six elements to be present. It does work for Hue, Sat & Lum just like I wanted. Thanks for your help.

Code:
Public Sub colortest()
   Dim varHSL As ColorProperties
   varHSL = RGBtoHSL(9902253)
   Debug.Print varHSL.red & ", " & varHSL.green & ", " & varHSL.blue
End Sub
 

petertheme

New member
Local time
Today, 11:02
Joined
Feb 25, 2022
Messages
12
I was hoping someone already hashed out the solution already but it looks like I'll be yanking out the VBA Handbook again. There has to be an algorithm for doing this to the RGB values or using that formula for the decimal value to simply change luminosity or in Minty's case the transparency. That slider in the pic I posted does exactly what I want so there must be a way to do it in VBA.

Having a solution to this would open the doors to creating theme color sets based on just two or three main colors. All the rest of the colors get set based on different levels of luminosity or shades. I'll keep plugging away at it.
I was hoping someone already hashed out the solution already but it looks like I'll be yanking out the VBA Handbook again. There has to be an algorithm for doing this to the RGB values or using that formula for the decimal value to simply change luminosity or in Minty's case the transparency. That slider in the pic I posted does exactly what I want so there must be a way to do it in VBA.

Having a solution to this would open the doors to creating theme color sets based on just two or three main colors. All the rest of the colors get set based on different levels of luminosity or shades. I'll keep plugging away at it.
I know it's late reply but Microsoft already included Themes in Access, starting in 2010.

Looking at a command button properties the Back Colour will be seen as
cmdBackcolor.png
it will show as
cmd1-office.png
by default using the "Office Theme"
and
cmd1-facet.png
with the Facet theme.

A theme contains 12 Base colors and has 100 darker and lighter variations. They use HSL the Hue being the Hue of the base color and the L value varying from full Tint (Lighter) which is White to full Shade (Darker) which is black.

HSL has been on the color picker for years, it was in 2003 and possibly earlier.
To get a lighter version of a color increase the L value and for darker decrease L.

It is possible to use VBA to adjust color using HSL. Examples from my ThemeMaker show using a slider starting from the orange in Accent 3 the slider has been moved to 70% lighter
lighter70pc.png


and in this example 35% darker.
darker35pc.png
 

Attachments

  • thememakerofficecolors.png
    thememakerofficecolors.png
    15.4 KB · Views: 79

Mike Krailo

Well-known member
Local time
Today, 07:02
Joined
Mar 28, 2020
Messages
1,030
Peter I appreciate your knowledge of themes and I have tried to use them. Unfortunately, after distributing my apps that use them, the original color designs get changed so I hate themes in that respect.

I guess I wanted to learn how to do some hard coded color settings quicker than the traditional method when designing forms. I believe I succeed with that goal. It was also fun figuring it all out.

I'll have to check out your theme maker app.
 

petertheme

New member
Local time
Today, 11:02
Joined
Feb 25, 2022
Messages
12
I would be interested in the details of how the colors changed. Since the current Theme is stored in the database opening the database on any other system will use the last stored theme. (Same applies to Word, Excel and Powerpoint)

If the database is supplied to users as an accdb they can go into a design and change the theme, which would change the colors and fonts.

To revert to the original theme they would need a copy of the relevant .thmx file
C:\Users\UserName \AppData\Roaming\Microsoft\Templates\Document Themes
folder.

You can supply that with the distribution or a better solution is to add code to the databases startup routine that extracts the theme from MSysResources and places it in the Documents Themes folder the first time the Database is opened by a new user.

This is not normally a problem for accde since design mode is not a possibility thus the theme gallery is not visible..

There are other possible complications when using custom themes created using the ribbon.
In your development database you can choose custom colors and save those to a given name the default is "Custom n" which is a number that increments with each use.
Saving creates a new color set in
C:\Users\Username\AppData\Roaming\Microsoft\Templates\Document Themes\Theme Colors

You can exit the database and open it again as many times as needed and the custom colors will remain. If you change theme the colors will reset to the colors from the selected theme.
To permanently keep the colors as a theme, in addition to saving the Color set, you need to go to the bottom of the theme gallery and choose "Save Current Theme". Unfortunately Microsoft do not prompt you to save the Theme after different colors or fonts have been applied. That is one of the many reasons I created my TMDThemeMaker.

In the worst case it is possible to save the theme with the new colors as "Office", however, you do have to confirm the Overwrite. The developer then has "Office.thmx" in their
C:\Users\UserName \AppData\Roaming\Microsoft\Templates\Document Themes
folder.
That would mean the developer could change themes but revert to their custom "Office" in the gallery when needed.

When the database is opened on an alternative PC then if the user tries some different themes but wants to go back to the original when they select "Office" in the gallery they will have the default colors, not your custom "Office" colors.

Please ask for clarification on anything that is not clear. I have been working with themes since 2013 so have spent a lot of time understanding the depths.

I have themed hundreds of databases with no unexpected problems.
 

SHANEMAC51

Active member
Local time
Today, 14:02
Joined
Jan 28, 2022
Messages
310
My current project requires some user defined colors to be entered into the form
quote from the internet
SECURE WEB COLORS
We offer you a palette of colors recommended for screen design. Safe colors are always the same when moving from one browser to another, from one monitor to another, or from one platform to another, with their different resolutions and color rendering capabilities.

If the web browser is not able to display a particular color correctly, then it tries to pick up a similar one or mixes several neighboring colors. It may happen that the original color will be replaced by something completely inappropriate.

Today, the expediency of using a secure palette is already very controversial, but using it, you will be sure that the colors will look consistently good and without distortion even on very old computers, up to an 8-bit display mode with support for only 256 colors.

Safe colors were derived mathematically, not because someone liked them more. To get a safe color from Red, Green and Blue, you need to use only these decimal values: 0, 51, 102, 153, 204, 255 — and no others. Each of the three hexadecimal values must not differ from 00, 33, 66, 99, CC, FF.

TABLE OF SAFE WEB COLORS
The palette consists of 216 secure web colors. Two values are indicated under each color - RGB, to create a color in a graphic editor, and its hexadecimal HEX code, to indicate a color in HTML.
 
Last edited:

Users who are viewing this thread

Top Bottom