Android Question if syntax with variable

DALB

Active Member
Licensed User
Hello,
is it possible to write something close to this syntax ?

Code:
Starter.vPays=If (valPays.Text=Null Then valPays.Text="")

Like I used in an other language (VBA : variable = iif (this boolean then that else thisOther)

Thank you.
 
somethink like this maybe?

Code:
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)
 
Upvote 0
+1 Manfred's solution, but... the example from post #1
Code:
Starter.vPays=If (valPays.Text=Null Then valPays.Text="")
which doesn't have an Else branch, looks like it is just meant to do this:
Code:
If valPays.Text = Null Then valPays.Text = ""
 
Last edited:
Upvote 0
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:
Code:
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
 
Upvote 0
Starter.vPays=If (valPays.Text=Null Then valPays.Text="")

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.

I'm probably missing something obvious here.
 
Upvote 0
I'm probably missing something obvious here.
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++.

Regards,

Anand
 
Upvote 0
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.
 
Upvote 0
I'm probably missing something obvious here.
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 :-)
 
Upvote 0
Back
Top