Hello, i need to convert a String in a Color. That i have the text “F9D97D” and i wold like that add it as color to a Window. I try with the “.val” but i can’t. Thanks in advance
If you have only “F9D97D” then you can use
dim c as variant = "F9D97D"
c = "&c" + c + "00"
Window1.BackColor = c.ColorValue
Thanks so much!!
Weird thing happened to me today.
When returning a color value, using the variant property .ColorValue I got a TypeMismatchException at runtime.
Even a try…catch block won’t stop the error from happening.
[code]Function ColorValue(propName as text, Default as color = &c000000) As Color
dim d as text = str(default).ToUTF8
if d.BeginsWith("&c") or d.BeginsWith("&h") then d = d.Mid(3)
dim t as text = Fields.Lookup( propName.Lowercase.Trim, d )
if not t.BeginsWith("&c") and not t.BeginsWith("&h") then t = “&c” + t
dim v as Variant = t
Return v.ColorValue
End Function[/code]
fields is a dictionary in the new framework. I am using this to make a Application Settings File.
The .ToUTF8 is just a confenience method that extends a string, and encodes it with UTF8 and returning it as TEXT
I finally got something to work by using CTYPE
c = color(ctype(val(t), integer))