Hexadecimal String to Color

  1. 3 months ago

    Martin T

    Dec 23 Pre-Release Testers Germany

    Hello everybody,

    i write color values as attributes to Xml files. The Attribute String looks like this: #RRGGBBAA. Now I wanna read the hexadecimal color string back to a color. How can I do that? I separate the RGBA values via String.Mid(start, length). But I need the integer value of the hex codes.

    I don’t wanna use the new Xojo Framework!

    Or this if you want to get more compact:

    Dim s As String = "#01020304"
    Dim c As Color = CType(s.Replace("#", "&c"), Variant)
  2. Julian S

    Dec 23 Pre-Release Testers, Xojo Pro UK
    Edited 3 months ago
    Dim s As String = "#01020304"
    Dim v As Variant = s.Replace("#", "&c")
    Dim c As Color = v
  3. Julian S

    Dec 23 Pre-Release Testers, Xojo Pro Answer UK
    Edited 3 months ago

    Or this if you want to get more compact:

    Dim s As String = "#01020304"
    Dim c As Color = CType(s.Replace("#", "&c"), Variant)
  4. Julian S

    Dec 23 Pre-Release Testers, Xojo Pro UK
    Edited 3 months ago

    Or this, but your input will be a string, so this is a wee bit overkill ;)

    Dim c As Color = CType(CType("#01020304", String).Replace("#", "&c"), Variant)
  5. Julian S

    Dec 23 Pre-Release Testers, Xojo Pro UK

    Or I could actually read your post again and give you what you asked for ;)

    Dim s As String = "#01020304"
    Dim c As Color = CType(s.Replace("#", "&c"), Variant)
    Dim r As Integer = c.Red
    Dim g As Integer = c.Green
    Dim b As Integer = c.Blue
    Dim a As Integer = c.Alphae

    I need some sleep :D

or Sign Up to reply!