Sign in to follow this  
Followers 0
jWalker

Number to HexColor ?!

10 posts in this topic

Is there a way to calculate an Hex value ( 00 - FF ) From a number from 0.0 to 1.0 ?

I made this here :)

Pretty shitty...

Switch $iAlpha
  Case 0.0 To 0.1
   $hColor = 0x00000000 + $hColor
  Case 0.1 To 0.2
   $hColor = 0x11000000 + $hColor
  Case 0.2 To 0.3
   $hColor = 0x33000000 + $hColor
  Case 0.3 To 0.4
   $hColor = 0x44000000 + $hColor
  Case 0.4 To 0.5
   $hColor = 0x66000000 + $hColor
  Case 0.5 To 0.6
   $hColor = 0x88000000 + $hColor
  Case 0.6 To 0.7
   $hColor = 0xAA000000 + $hColor
  Case 0.7 To 0.8
   $hColor = 0xBB000000 + $hColor
  Case 0.8 To 0.9
   $hColor = 0xDD000000 + $hColor
  Case 0.9 To 1.0
   $hColor = 0xFF000000 + $hColor
  Case Else
   $hColor = 0xFF000000 + $hColor
EndSwitch

Share this post


Link to post
Share on other sites



00 - FF in hex is 000 - 255 in decimal. So multiply the decimal value by 255 and convert it to hex.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

U make me look su dumb haha ;)

Thank you :)

Share this post


Link to post
Share on other sites

I wish all questions were that easy :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

i just have to use _StringToHex or?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Or just:

$Number = .1
$Hex = Hex(Int($Number * 255), 2)
ConsoleWrite($Hex & @CRLF)

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Much better

Share this post


Link to post
Share on other sites

This confuses me a lot :)

I have an RGB Hex

0xFF0000 - Red

Now i have Alpha 1

FF

Normally - converting RGB to ARGB is just adding them both together or?

It should look like:

0xFF000000 + 0xFF0000 = 0xFFFF0000

But it doesn't work for me here

$hAlpha = Hex( Int( 255 * $iAlpha ;1; ) , 2 )

$hAlpha = FF

There is no 0x ??

Share this post


Link to post
Share on other sites

This example should explain.

Local $iAlpha, $hColor = 0x123456

For $i = 0 To 10
    $iAlpha = $i / 10

    $hColor = Execute("0x" & Hex(Int($i * 255 / 10), 2) & Hex($hColor, 6))

    ConsoleWrite("Alpha = " & $iAlpha & @TAB & "  Color =  Dec " & $hColor & @TAB & " or Hex 0x" & Hex($hColor, 8) & @LF)
Next


$iAlpha = 0.5
Local $argb = Int(255 * $iAlpha) * 0x1000000 + $hColor
ConsoleWrite($argb & " or 0x" & Hex($argb, 8) & @LF)

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Huhm

I actually had it right all the time

But i didn't know that if i display 0xFFFF0000 in a tooltip, that the 0x gets deleted -.-

Edited by jWalker

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0