Bug? IIF statement breaks CHAR

LucasHeer

Active Member
Licensed User
Longtime User
Good afternoon!

I really would not consider this a bug, there is easy to workaround, but took a second to figure it out.

This is my B4A code:
B4X:
    settings_toggle_guidelines.Text = IIf(enabled_guidelines, Chr(0xf205), Chr(0xf204))
    settings_toggle_levelindicator.Text = IIf(enabled_levelindicator, Chr(0xf205), Chr(0xf204))
    settings_toggle_templatestencil.Text = IIf(enabled_templatestencil, Chr(0xf205), Chr(0xf204))


This works perfect in B4A, but in B4I -- It causes the FontAwesome assigned label to show "61956" -- The decimal version of the hex sent to Chr().

I did a unit test to see what exactly is going on:
B4X:
    Dim result As Object = IIf(enabled_guidelines, Chr(0xf205), Chr(0xf204))
    Log("IIF object type: " & GetType(result) & " " & result)
    Log("NON object type: " & GetType(Chr(0xf205)) & " " & Chr(0xf205))

1771155987769.png


The workaround was:
B4X:
    If(enabled_guidelines) Then
        settings_toggle_guidelines.Text = Chr(0xf205)
    Else
        settings_toggle_guidelines.Text = Chr(0xf204)
    End If
    If(enabled_levelindicator) Then
        settings_toggle_levelindicator.Text = Chr(0xf205)
    Else
        settings_toggle_levelindicator.Text = Chr(0xf204)
    End If
    If(enabled_templatestencil) Then
        settings_toggle_templatestencil.Text = Chr(0xf205)
    Else
        settings_toggle_templatestencil.Text = Chr(0xf204)
    End If

Edit:
No -- this is the workaround:
B4X:
    settings_toggle_guidelines.Text = Chr(IIf(enabled_guidelines, 0xf205, 0xf204))
    settings_toggle_levelindicator.Text = Chr(IIf(enabled_levelindicator, 0xf205, 0xf204))
    settings_toggle_templatestencil.Text = Chr(IIf(enabled_templatestencil, 0xf205, 0xf204))


Thank you!!
 
Top