Erel B4X founder Staff member Licensed User Longtime User Feb 25, 2012 #2 There is no iif function. You can add it yourself: Code: Copy Sub IIF(c As boolean, TrueRes As String, FalseRes As String) If c Then Return TrueRes Else Return FalseRes End Sub ... Log(IIF (2 > 3, "yes", "no"))
There is no iif function. You can add it yourself: Code: Copy Sub IIF(c As boolean, TrueRes As String, FalseRes As String) If c Then Return TrueRes Else Return FalseRes End Sub ... Log(IIF (2 > 3, "yes", "no"))
S silverbyte Member Licensed User Longtime User Mar 29, 2013 #3 Erel said: There is no iif function. You can add it yourself: Code: Copy Sub IIF(c As boolean, TrueRes As String, FalseRes As String) If c Then Return TrueRes Else Return FalseRes End Sub ... Log(IIF (2 > 3, "yes", "no")) Click to expand... Not the best solution. Lets say I want to return a boolean, array, object etc etc.. Since b4a doesn't support overloading methods YET, IIF isn't really practical I would need IIF for every returntype. Unless theres a solution to that? casting variables?? Another consideration is the following (in C language) (1 = 2) ? true : false ==> returns false Yes I know this is the same as IF ELSE although im writing some code that needs TONS of these conditions and write ifelse everywhere will just make it look yucky.
Erel said: There is no iif function. You can add it yourself: Code: Copy Sub IIF(c As boolean, TrueRes As String, FalseRes As String) If c Then Return TrueRes Else Return FalseRes End Sub ... Log(IIF (2 > 3, "yes", "no")) Click to expand... Not the best solution. Lets say I want to return a boolean, array, object etc etc.. Since b4a doesn't support overloading methods YET, IIF isn't really practical I would need IIF for every returntype. Unless theres a solution to that? casting variables?? Another consideration is the following (in C language) (1 = 2) ? true : false ==> returns false Yes I know this is the same as IF ELSE although im writing some code that needs TONS of these conditions and write ifelse everywhere will just make it look yucky.
agraham Expert Licensed User Longtime User Mar 29, 2013 #4 It should work using Object parameters as long as you assign the return to the correct type of variable or one compatible for which Basic4android can do the automatic conversion. e.g a String numeric to an Int. Code: Copy Sub IIF(c As Boolean, TrueRes As Object, FalseRes As Object) As Object If c Then Return TrueRes Else Return FalseRes End Sub Last edited: Mar 29, 2013
It should work using Object parameters as long as you assign the return to the correct type of variable or one compatible for which Basic4android can do the automatic conversion. e.g a String numeric to an Int. Code: Copy Sub IIF(c As Boolean, TrueRes As Object, FalseRes As Object) As Object If c Then Return TrueRes Else Return FalseRes End Sub
margret Well-Known Member Licensed User Longtime User Mar 29, 2013 #5 I use this in my String Functions module. It is dimmed as strings and works with numbers, strings or booleans. I have used it this way for more than a year and in many apps with no problem. B4A is very smart handling this!!
I use this in my String Functions module. It is dimmed as strings and works with numbers, strings or booleans. I have used it this way for more than a year and in many apps with no problem. B4A is very smart handling this!!
agraham Expert Licensed User Longtime User Mar 29, 2013 #6 Perhaps I should emphasise that by using Object as the parameter and return type you should be able to use just any reference type as well primitives, arrays, custom types, Views etc. Basic4android will generally convert primitive values to other primitive values but reference types need the return assigned to a compatible type.
Perhaps I should emphasise that by using Object as the parameter and return type you should be able to use just any reference type as well primitives, arrays, custom types, Views etc. Basic4android will generally convert primitive values to other primitive values but reference types need the return assigned to a compatible type.
S silverbyte Member Licensed User Longtime User Mar 29, 2013 #7 agraham said: It should work using Object parameters as long as you assign the return to the correct type of variable or one compatible for which Basic4android can do the automatic conversion. e.g a String numeric to an Int. Code: Copy Sub IIF(c As Boolean, TrueRes As Object, FalseRes As Object) As Object If c Then Return TrueRes Else Return FalseRes End Sub Click to expand... Thanks agraham! i'll give that a try
agraham said: It should work using Object parameters as long as you assign the return to the correct type of variable or one compatible for which Basic4android can do the automatic conversion. e.g a String numeric to an Int. Code: Copy Sub IIF(c As Boolean, TrueRes As Object, FalseRes As Object) As Object If c Then Return TrueRes Else Return FalseRes End Sub Click to expand... Thanks agraham! i'll give that a try