Wish B4X IIF Function

DonManfred

Expert
Licensed User
Longtime User
I need it too.
Add the sub to your project and you can use it. No need to change the core.
You can also make a small library out of it and use the newly created library in your project(s).
 

Martin Larsen

Active Member
Licensed User
Longtime User
Sure, but you could say the same for many core routines. I find IIF so useful it should be part of core or at least a standard lib of some kind.
 

MrKim

Well-Known Member
Licensed User
Longtime User
I didn't write that you can't ask for what you want :oops:

Indeed, I think it is a fair request but since we all, I think, have some routines we use in every project (utility routines)...!
Yes, but this is not a favorite utility. IIF has been core to MS Basic since - Forever? - For thirty years it has been just THERE. Are there popular versions of Basic that DON'T have IIF (Besides B4X)?
 

LucaMs

Expert
Licensed User
Longtime User
Yes, but this is not a favorite utility. IIF has been core to MS Basic since - Forever? - For thirty years it has been just THERE. Are there popular versions of Basic that DON'T have IIF (Besides B4X)?
B4X is not VB6; in this there were also other functions that do not exist in B4X (eg InStrRev, Left, Right, Space... to mention only string functions) or have different names.

Anyway, adding IIF could be useful.
 

MrKim

Well-Known Member
Licensed User
Longtime User
B4X is not VB6; in this there were also other functions that do not exist in B4X (eg InStrRev, Left, Right, Space... to mention only string functions) or have different names.

Anyway, adding IIF could be useful.
Yes, but there are easy B4X solutions to all of those and, (I think) those are all used relatively infrequently. IIF is not. You know MS finally even added IIF to SQL server. As I understand it is simply converted to a CASE statement in the background which is ANSII compatible. But code is so much more readable with an IIF rather than a case.
 

LucaMs

Expert
Licensed User
Longtime User
A crash occurs because IsNumber is not "computed" / evaluated and only then its result passed to the IIF function.
and also the second calculation.


Not if you test it with:
B4X:
Label1.Text = IIf(IsNumber(EditText1.Text), EditText1.Text * 10, "Invalid number")
;)
Yes, it is anyway, because:

1 - it is better to use a variable, not a UI element (keep graphics and data/logic separate)
2 - it is better not to use literals (10 and "Invalid number")

I always have to work hard to teach you the basics of programming; when will you learn? 😂
 
Top