Android Code Snippet Smart Text

Hey guys,

I just want to share a useful function I created:
B4X:
Sub IfTrue(check_var As Boolean, true_result As Object, false_result As Object) As String
        If check_var = True Then
            Return true_result
        Else
            Return false_result
        End If
End Sub


Usage:
B4X:
Dim This_Glass_Is_Full = True as Boolean
...
label1.text = "The glass is " & IfTrue(This_Glass_Is_Full, "full. Click here to drink.", "empty. Click here to refill.")


Output:
The glass is full. Click here to drink.
(This_Glass_Is_Full = True)


The glass is empty. Click here to refill.
(This_Glass_Is_Full = False)

 
Last edited:

wonder

Expert
Licensed User
Top