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:

Cableguy

Expert
Licensed User
Longtime User
Interesting usage... I never thought we could do logical testing within a string set parameter.
 

wonder

Expert
Licensed User
Longtime User

Cableguy

Expert
Licensed User
Longtime User
Great... Looks like I just "reinvented the wheel". :(
Even the wheel keeps getting reinvented... From stone to wood, from wood to steel... Then " someone" added rubber to that equation and we got tubed wheels...
Yours is like... Tubeless and flat-proof!!!
 
Top