Sub IIf(Condition As Boolean, Yes As Object, No As Object) As Object
If Condition Then Return Yes Else Return No
End Sub
'
'Usage
Starter.vPays=IfF((valPays.Text=Null),"",valPays.Text)
For the example you gave, given that a program that needs it is likely to use it a lot, it might be better to write a type-specific function eg:
B4X:
Sub NullToString(S As String) As String
If S = Null Then
Return ""
End If
Return S
End Sub
'Usage (and readability comparison)
Starter.vPays = NullToString(Starter.vPays) 'type-specific function
Starter.vPays=IfF((valPays.Text=Null),"",valPays.Text) 'general function
I spent a couple of minutes trying to parse this and I can't even begin to understand what's supposed to happen. Can you walk me through it like I'm five?
Note: I've seen DonManfreds suggestion, and tried to use that as a guide to undersanding the example by DALB, but I can't see how they relate really. I mean, DonManfred is basically creating a simple ternary operator, but I can't see how that relates to the original question.
Agree.
Either original question is wrong/not what was intended, or we understood it differently and gave solution for IIF(cond, true, false) syntax which is available in some languages including Clipper/Xbase++.
ok yes, there is not a native function, I must create a sub for this.
I'm a really lazy man and copy ans paste is my favorite action.
But here, sub as DonManfred shows the example creates 3 lines, and I must add my own one...total = 4 lines.
Yes, it's necessary to create my own solution (sub)
Thanks to everyone.
To be fair to DALB, and especially given that he specified "something close", the pseudocode seemed pretty clear to me. And Manfred* too. Perhaps the C-style assignment-within-expressions and ternary operators don't jump off the page to hardcore dedicated BASIC programmers.
There is a missing closing bracket around the VBA reference, but we've all done that at least once ;-)
* the King of Precision Literal Interpretation - but I do appreciate the accuracy that he adds to my hand-wavy approximations