Page 1 of 1

return hex value of chosen color

Posted: Mon Sep 16, 2013 9:16 pm
by ThomasBodetti
Hello, I am looking at how to return the chosen color of a value in its Hex value

Code: Select all

 get the backgroundcolor of control ID "1003" 
   put it into myColorVar
   put myColorVar into fld "colorID"
This will create an RGB value, like 22,183,67 for a blue

how would I get the hex value of that same value, like this, #0000FF

Thanks for any guidence and or suggestions

Re: return hex value of chosen color

Posted: Mon Sep 16, 2013 9:27 pm
by Simon
Here you go :)

Code: Select all

   repeat with x =1 to the number of items in myColorVar
      put baseconvert(item x of myColorVar,10,16) after tHex
   end repeat
Fun!

Simon

Re: return hex value of chosen color

Posted: Mon Sep 16, 2013 9:41 pm
by Simon
Ok more accurately:

Code: Select all

   repeat with x =1 to the number of items in myColorVar
      put baseconvert(item x of myColorVar,10,16) into tHex
      if the number of chars in tHex < 2 then
         put "0" before tHex
      end if
      put tHex after myHexColorVar
   end repeat
   put "#" before myHexColorVar
That will make it look the way you want.

Simon

Re: return hex value of chosen color

Posted: Mon Sep 16, 2013 9:45 pm
by ThomasBodetti
Thank you Simon, That works perfectly.

They should add that to the dictionary and manual.

Re: return hex value of chosen color

Posted: Tue Sep 17, 2013 1:54 am
by Simon
Hi Thomas,
Actually I didn't know how to do it but the word "convert" popped into my head, 'cause it's what you were asking for. Just a search on "convert" in the dictionary showed me how to do it.

The English-like language of liveCode makes it easier to look up ideas and find answers.

At any rate, glad I could help you.

Simon