# Number to HexColor ?!

## Recommended Posts

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

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 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 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
WebDriver - Wiki

##### Share on other sites

U make me look su dumb haha

Thank you

##### Share on other sites

I wish all questions were that easy

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
WebDriver - Wiki

##### Share on other sites

i just have to use _StringToHex or?

##### Share on other sites

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 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
WebDriver - Wiki

Much better

##### 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 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 on other sites

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

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...