PDA

View Full Version : dialog_choosecolor returned number



sandyrepope
25-11-2007, 23:51
I'm having a problem with understanding the number returned by dialog_choosecolor. I'm not sure just what the number means.

What I need to do with the number is change it to fit the parameters required for the RGB command. RGB requires three numbers as in this example:

RGB( 255 , 0 , 0)

I can do the coding if I just knew what is the best way to convert the number.

Can anyone help with this?

Thanks
Sandy

Michael Clease
26-11-2007, 00:24
The number returned is and 0BGR.

If you are using this for UI stuff ie. Control set Color you dont need to convert the number you just use it.

you only use RGB(xxx,xxx,xxx) to combine seperate R,G,B values.

Heres a modified example.




uses "UI"

DIM sMsg as STRING
dim lColor as long
DIM R as long
DIM G as long
DIM B as long
Dim Colour as LONG
lColor = Dialog_ChooseColor(0, rgb(255, 0, 0), %CC_RGBINIT OR %CC_FULLOPEN )

if lColor = -1 then
msgbox 0, "Color Dialog cancel by user"
else
B = LColor AND &h00FF0000
G = LColor AND &h0000FF00
R = LColor AND &h000000FF
sMsg = "Red" + $TAB +"=" + $TAB + HEX$(R,6) + $CRLF
sMsg += "Green" + $TAB +"=" + $TAB + HEX$(G,6) + $CRLF
sMsg += "Blue" + $TAB +"=" + $TAB + HEX$(B,6) + $CRLF + $CRLF
SHIFT SIGNED RIGHT B,16
SHIFT SIGNED LEFT R,16
Colour = R OR G OR B
sMsg += "Shifted to Correct Possitions" + $CRLF + $CRLF
sMsg += "Red" + $TAB +"=" + $TAB + HEX$(R,6) + $CRLF
sMsg += "Green" + $TAB +"=" + $TAB + HEX$(G,6) + $CRLF
sMsg += "Blue" + $TAB +"=" + $TAB + HEX$(B,6) + $CRLF + $CRLF

sMsg += "Your color is: " & hex$(lCOlor, 6) + $CRLF +$CRLF
sMsg += " New RGB Colour is: " + HEX$(Colour,6) + $CRLF + $CRLF
msgbox 0, sMsg

end if


update: I didnt test properly its actually 0BGR not as first thought 0RGB

sandyrepope
26-11-2007, 00:46
Abraxas, I appreciate your script but....... it doesn't always return the correct numbers in r, g, b.

Sorry, but I ran the script several times and sometimes it's correct and sometimes not.

Thanks
Sandy

question: if I use hex$ to get the hex of the number and use mid$ to pull out the two digit numbers then... how can I change the hex number to a 10-based number?

Michael Clease
26-11-2007, 00:55
Sorry Sandy my mistake works now. :-[

Petr Schreiber
26-11-2007, 10:39
Hi,



if I use hex$ to get the hex of the number and use mid$ to pull out the two digit numbers then... how can I change the hex number to a 10-based number?


You could try something based on following:


dim MyHexString as string = "FF"
dim MyDecValue as long

MyDecValue = val("&h"+MyHexString)

msgbox 0, MyDecValue



Bye,
Petr

sandyrepope
26-11-2007, 16:46
dim MyHexString as string = "FF"
dim MyDecValue as long

MyDecValue = val("&h"+MyHexString)

msgbox 0, MyDecValue

Thank you, Petr, this does what I needed. It works.

Sandy