I have a textbox with two expressions in it that shows a total and a percentage in it. It's this format:
TOTAL (percentage) . . . for example 956 (8.35%)
I wrote a quick function to parse out the percentage from the text-box value as a decimal and then return a color based on the parsed out value:
Public Function ColorCodeDown(s As String) As String 'Parse out percent Dim First As Integer = s.IndexOf("(") Dim Second As Integer = s.IndexOf(")") Dim MyPercent As Decimal = Convert.ToDecimal(s.Substring(First + 1, Second - First - 1)) 'Get a color based on value Dim MyColor As String IF MyPercent > 0.90 Then MyColor = "#2FA385" ElseIf MyPercent > 0.80 Then MyColor = "#32B15D" ElseIf MyPercent > 0.70 Then MyColor = "#38BF9D" ElseIf MyPercent > 0.60 Then MyColor = "#3DD16B" ElseIf MyPercent > 0.50 Then MyColor = "#F0C427" ElseIf MyPercent > 0.40 Then MyColor = "#F29C22" ElseIf MyPercent > 0.30 Then MyColor = "#E37B1C" ElseIf MyPercent > 0.20 Then MyColor = "#D14F16" ElseIf MyPercent > 0.10 Then MyColor = "#E44233" Else MyColor = "#BE3023" End If Return MyColor End Function
This function works as expected when setting the background color property on the textbox =Code.ColorCodeDown(Me.Value), however doing the same thing to the color property just colors it black. Additionally, setting the tooltip to =Code.ColorCodeDown(Me.Value) gives the expected hex value when you hover over it.
Any ideas? Thanks in advance!