Brian Dunning's FileMaker Custom Functions

HexToRGB ( Hex ; RGorB )

Returns a decimal integer that represents a color obtained by converting standard 6 character hexadecimal input.

  Average rating: 4.2 (40 votes) Log in to vote

Jeremiah Small   Jeremiah Small - Show more from this author
Soliant Consulting, Inc.
https://www.soliantconsulting.com

Share on Facebook Share on Twitter

  Sample input:
HexToRGB ( "#FFFF00" ; "R" )
HexToRGB ( "#FFFF00" ; "RGB" )
  Sample output:
255
16776960

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

Returns an integer that represents a color obtained by converting standard 6 character hexadecimal input.
If you pass any value to the RGorB param other than "R" or "G" or "B" the function will return the full spectrum decimal value.
The RGorB parameter is a switch modifies the calculation to return only the red, green or blue decimal value of Hex.

Hex = Hexadecimal input. Handles inputs containing leading/trailing spaces and/or # symbol.

RGorB = Switch that determines the spectrum of output ( "R" = red; "G" = green; "B" = Blue; "RGB" or "0" or [not null] = RGB ).

 

Comments

Nick Lightbody   Nick Lightbody, Deskspace Systems Limited
Aug 28, 2016
Just a quick thanks Jeremy, you donated this many years ago and today it very neatly solved a problem for me.
Cheers, Nick
 
Math   Math, Paris, France
Aug 22, 2017
Exactly what I search. it's works well, Thanx.
 
Tom Guise   Tom Guise, Smart Wolf
Apr 4, 2022
Thanks Jeremiah!

I'm using this to covert Hex to the RGBA format required for Javascript charts using Chart.js as follows (incase it's useful for anybody else reading this):

// Requires: HexToRGB
// https://www.briandunning.com/cf/115

Let (
[

R = HexToRGB ( Hex ; "R" ) ; // Red
G = HexToRGB ( Hex ; "G" ) ; // Green
B = HexToRGB ( Hex ; "B" ) ; // Blue
A = 1 // Alpha

]

;

"rgba(" & R & "," & G & "," & B & "," & A & ")"

)
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: