jWalker Posted January 23, 2012 Posted January 23, 2012 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
water Posted January 23, 2012 Posted January 23, 2012 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 2024-07-28 - Version 1.6.3.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 (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
water Posted January 23, 2012 Posted January 23, 2012 I wish all questions were that easy My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
water Posted January 23, 2012 Posted January 23, 2012 (edited) Or just:$Number = .1 $Hex = Hex(Int($Number * 255), 2) ConsoleWrite($Hex & @CRLF) Edited January 23, 2012 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
jWalker Posted January 23, 2012 Author Posted January 23, 2012 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 ??
Malkey Posted January 23, 2012 Posted January 23, 2012 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)
jWalker Posted January 23, 2012 Author Posted January 23, 2012 (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 January 23, 2012 by jWalker
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now