Jump to content

Number to HexColor ?!


jWalker
 Share

Recommended Posts

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
Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

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

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I wish all questions were that easy :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

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

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

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

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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 ??

Link to comment
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)
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...