HEX COLOR

Wednesday, August 18, 2004 by doodmon | Discussion: WinCustomize Talk

OK... I'm tryin to single out each color (red, green, blue) from a hex color string... here is my code:

sub on_objecttimer456
'get the hexidecimal number of the current color of text
hexcolor = hex(me.textcolor)
'find each color
red = right(hexcolor,2)
green = mid(hexcolor,2,2)
blue = left(hexcolor,2)
end sub

My problem is that if hexcolor has any zeros in it, they don't seem to wanna show in hexcolor... like it auto-trims or somethin...
example:
sub on_objecttimer456
me.textcolor = RGB(255,0,0)
'hexcolor of that should be FF0000
hexcolor = hex(me.textcolor)

'result of me.textcolor value is 255
msgbox me.textcolor

'result of hex(me.textcolor) is FF (not FF0000)
msgbox hexcolor
end sub
paxx
Reply #1 Wednesday, August 18, 2004 8:05 AM

Maybe if you convert the value into a text string not an integer.

doodmon
Reply #2 Wednesday, August 18, 2004 8:11 AM
how would I do this.... it's a little different than VB... i can't just dim hexcolor as string
paxx
Reply #3 Wednesday, August 18, 2004 8:55 AM

I haven't played a whole lot with DX, let me try a few things.

BTW: your code is screwed up...  It make no sense anyway as far as I understand DX script.

You wrote "sub on_objecttimer456", but I think it should be "sub Object_onTimer456".  You did define the timer first, right? ex: "Object.SetTimer 456, 10000". And I'm not sure how you are actually executing this script. Do you have actually two onTimer events? Not sure that would work.

paxx
Reply #4 Wednesday, August 18, 2004 10:16 AM

OK, here is what I did.  I probably cheated, there mist be a better way, but this works anyway.
The problem is that the Hex function seem to drop the trailing zeros. I looked it up and it seems to be a VBS thing, not specificly DX.  Anyway, I'm just adding back the zeros that got dropped:

 

Sub Object_OnScriptEnter
  Me.textcolor = RGB(255,0,0)
    HexValue = Hex(Me.textcolor)
    thislength = Len(HexValue)
   
    If (thislength = 1) Then
     HexValue = HexValue & "00000"
    ElseIf (thislength = 2) Then
     HexValue = HexValue & "0000"
    ElseIf (thislength = 3) Then
     HexValue = HexValue & "000"
    ElseIf (thislength = 4) Then
     HexValue = HexValue & "00"
    ElseIf (thisLength = 5) Then
     HexValue = Hexvalue & "0"
    End If
      
  red = left(HexValue,2)
  green = Mid(HexValue,3,2)
  blue = right(HexValue,2)    

    
    msgbox "R:" & red & " G:" & green & " B:" & blue
   
End Sub


[Message Edited]
Kevin_C
Reply #5 Wednesday, August 18, 2004 11:17 AM
well, you could use a loop and add a zero until the length is 6.

for(var i = 0 HexValue.length == 6 i++)
HexValue += "0"

I leave it to you to convert this to VBScript.. I'm not fond of VB's syntax and so avoid it at all costs..
craeonics
Reply #6 Wednesday, August 18, 2004 11:36 AM
You should definitely not fill till you have six digits. Hexadecimal colour description consists of three two digit numbers (rrggbb), not one six digit number. Just adding a zero to the end of the string would produce rubbish.
CerebroJD
Reply #7 Wednesday, August 18, 2004 12:01 PM
Wait....nevermind.
[Message Edited]
doodmon
Reply #8 Wednesday, August 18, 2004 12:55 PM
Thanks guys... I was able to use some of your ideas to get it working... I tested out that script a little more and figured out that if you have blue the HexValue code puts out FF0000 (which is bassackwards in my book RRGGBB)
so instead of adding the zeros to the end of it, I added it to the front... and instead of red ing the first two digits on left... i the first two digits on right... here is what I mean:

Sub Object_OnTimer54987
Me.textcolor = RGB(171,12,255)

HexValue = Hex(Me.textcolor)
thislength = Len(HexValue)

If (thislength = 1) Then
HexValue = "00000"& HexValue
ElseIf (thislength = 2) Then
HexValue = "0000"& HexValue
ElseIf (thislength = 3) Then
HexValue = "000" & HexValue
ElseIf (thislength = 4) Then
HexValue = "00"& HexValue
ElseIf (thisLength = 5) Then
HexValue = "0" & Hexvalue
End If

red = right(HexValue,2)
green = Mid(HexValue,3,2)
blue = left(HexValue,2)
msgbox HexValue & "," & red & "," & green & "," & blue



End Sub



seems to be working...
doodmon
Reply #9 Wednesday, August 18, 2004 12:58 PM
whoa... lots of typo's ... "and instead of READING the first two digits on the left... it reads the first two on right"

Please login to comment and/or vote for this skin.

Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:

  • Richer content, access to many features that are disabled for guests like commenting on the forums and downloading skins.
  • Access to a great community, with a massive database of many, many areas of interest.
  • Access to contests & subscription offers like exclusive emails.
  • It's simple, and FREE!



web-wc01