Hex2RGB ( hex ; delimiter ; alert )

Version 2

     

    Custom Function

     

    Compatibility
    Creator
    Mac OS X, Windows
    F. Osman CABI
    FMP 7, 8, 8.5, 9, 10, 11
    Cabitas Ltd.
    Web: Yes
    File Type: None
    Server: Yes
    FileSize: 0 kilobytes
    http://www.cabitas.com

    Description

    Simply Converts hex color codes to decimal RGB. Hex2RGB function converts standard hex color codes (generally used in html web sites) into RGB. Hex color codes is form of 6 or 7 (with #) characters. R is first two characters in hex format, G is next two characters in hex format and B is last two characters in hex format. For example "#FF00AA" is converted as decimal RBG as following : (171;205;239)

     


    Code

    Let (

     

    // Check input value

    chex = Upper ( Filter ( hex ; "0123456789aAbBcCdDeEfF" ) ) ;

    If ( Length ( chex ) = 6 ;

     

    // RED

    Substitute ( Middle ( chex;1;1) ; [ "A" ; 10 ] ; [ "B" ; 11 ] ; [ "C" ; 12 ] ; [ "D" ; 13 ] ; [ "E" ; 14 ] ; [ "F" ; 15 ] ) * 16 +

    Substitute ( Middle ( chex;2;1) ; [ "A" ; 10 ] ; [ "B" ; 11 ] ; [ "C" ; 12 ] ; [ "D" ; 13 ] ; [ "E" ; 14 ] ; [ "F" ; 15 ] ) * 1 & delimiter &

     

    // GREEN

    Substitute ( Middle (chex;3;1) ; [ "A" ; 10 ] ; [ "B" ; 11 ] ; [ "C" ; 12 ] ; [ "D" ; 13 ] ; [ "E" ; 14 ] ; [ "F" ; 15 ] ) * 16 +

    Substitute ( Middle (chex;4;1) ; [ "A" ; 10 ] ; [ "B" ; 11 ] ; [ "C" ; 12 ] ; [ "D" ; 13 ] ; [ "E" ; 14 ] ; [ "F" ; 15 ] ) * 1 & delimiter &

     

    // BLUE

    Substitute ( Middle (chex;5;1) ; [ "A" ; 10 ] ; [ "B" ; 11 ] ; [ "C" ; 12 ] ; [ "D" ; 13 ] ; [ "E" ; 14 ] ; [ "F" ; 15 ] ) * 16 +

    Substitute ( Middle (chex;6;1) ; [ "A" ; 10 ] ; [ "B" ; 11 ] ; [ "C" ; 12 ] ; [ "D" ; 13 ] ; [ "E" ; 14 ] ; [ "F" ; 15 ] ) * 1

     

    ; alert ) )

     

    Sample Input

    Sample Output
    Hex2RGB ( "0CAB10" ; "-" ; "Hex is written wrong" )

    12-171-16

    Developer's Notes

     

     


    FileMaker Inc. provides this content on an “As Is” basis, without any warranty, and subject to the terms of the FileMaker Technical Network Agreement. FileMaker makes no representations and is not liable for any content or related information. You may use the content as part of your own solutions and for your customers, but you may not otherwise publicly distribute any content that you did not submit. ©2009-2011 FileMaker, Inc. All Rights Reserved. FileMaker is a trademark of FileMaker, Inc. registered in the U.S. and other countries.