Wish B4X IIF Function

MrKim

Well-Known Member
Licensed User
Longtime User
Not if you test it with:
B4X:
Label1.Text = IIf(IsNumber(EditText1.Text), EditText1.Text * 10, "Invalid number")
Good to know, actually, because as I recall in VBA you can't do that because IIF evaluates ALL of the responses, even if they are not used. So your example would fail with an invalid number.
 

LucaMs

Expert
Licensed User
Longtime User
Why not CHOOSE(condition,trueval,falseval) ?, there is no need to be cryptic.
IIF is an existing .Net function.
CHOOSE also exists, although I don't understand its usefulness, since it corresponds to:
B4X:
Public Sub Choose(Index As Int, Values() As Object) As Object
    Return Values(Index)
End Sub
Why not write directly:
B4X:
Dim MyVariable As Int = Values(SomeIndex)
?
 

WhiteWizard

Member
Licensed User
Pity about the CHOOSE operator, I'm a Clarion programmer and I like that minimalistic languaje, for ex, we only have a LOOP command for LOOPs:
LOOP F = 1 TO N (BY step)
. (or END at your preference)
LOOP UNTIL/WHILE
just LOOP.
 

LucaMs

Expert
Licensed User
Longtime User
Pity about the CHOOSE operator, I'm a Clarion programmer and I like that minimalistic languaje, for ex, we only have a LOOP command for LOOPs:
LOOP F = 1 TO N (BY step)
. (or END at your preference)
LOOP UNTIL/WHILE
just LOOP.
Well, having two distinct:
B4X:
For Each...

Do Until/While...
I think is better, more easily readable and logical.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…