(12-21-2024, 12:02 AM)Pete Wrote: Petr's example as a string I think would be...I haven't used the new _IIF command yet, but in VBA (and VB6 if I recall?) you could use IIF to return multiple types.
Code: (Select All)Dim result as String
a$ = "Yes"
result = _IIf(a$ = "YES", "a$ is YES", "a$ is not YES" )
Print result
I say think because I haven't downloaded and installed the new version yet.
Someone please correct Steve if I am wrong.
Pete
In QB64 / QB64PE, I had to make seperate functions for different return types, like below, but it would be nice if the built-in _IIF command just worked with whatever type you passed in for parameters 2 & 3 (as long as parameters 2 & 3 aren't 2 different types)...
Code: (Select All)
'Integer
Function IIF% (Condition, IfTrue%, IfFalse%)
If Condition Then IIF% = IfTrue% Else IIF% = IfFalse%
End Function
'String
Function IIFS$ (Condition, IfTrue$, IfFalse$)
If Condition Then IIFS$ = IfTrue$ Else IIFS$ = IfFalse$
End Function
'Long
Function IIFL& (Condition, IfTrue&, IfFalse&)
If Condition Then IIFL& = IfTrue& Else IIFL& = IfFalse&
End Function
'Single
Function IIFSng! (Condition, IfTrue!, IfFalse!)
If Condition Then IIFSng! = IfTrue! Else IIFSng! = IfFalse!
End Function
'Double
Function IIFDbl# (Condition, IfTrue#, IfFalse#)
If Condition Then IIFDbl# = IfTrue# Else IIFDbl# = IfFalse#
End Function
'Float
Function IIFF## (Condition, IfTrue##, IfFalse##)
If Condition Then IIFF## = IfTrue## Else IIFF## = IfFalse##
End Function
'Unsigned Integer
Function IIFUI~% (Condition, IfTrue~%, IfFalse~%)
If Condition Then IIFUI~% = IfTrue~% Else IIFSTR$ = IfFalse~%
End Function
'Etc.