1.Run the next Basic script. Sub Test1 Dim i As Long, arr arr=IIf(i=0, Array(), Array(0)) End Sub An error occurs that must not occur. 2.Run the next Basic script. Sub Test2 Dim i As Long, arr arr=IIf(i=1, Array(), Array(0)) Msgbox IsArray(arr) End Sub Returns False, must be True.
I can reproduce the error in LO 7.3. I also tried the following variation: Sub TestA Dim i as Long, arr, a, b i = 0 a = Array() b = Array(0) arr = Iif(i = 0, a, b) End Sub Which returned the error "Inadmissible value or data type. Index out of defined range." This does not seem to make sense since we're not trying to access internal data of the array. This issue has something to do with the Array object. The following code runs without issues: Sub TestB Dim i as Long, arr, a, b i = 0 a = 3 b = 4 arr = Iif(i = 0, a, b) End Sub System info: Version: 7.3.3.2 / LibreOffice Community Build ID: 30(Build:2) CPU threads: 12; OS: Linux 5.13; UI render: default; VCL: kf5 (cairo+xcb) Locale: pt-BR (pt_BR.UTF-8); UI: en-US Ubuntu package version: 1:7.3.3~rc2-0ubuntu0.21.10.1~lo1 Calc: threaded
Already in 6.0.0.3.
It seems that IIF evaluate both values before give a return value. In PitonYack pag 77 : "The IIf (“Immediate If”) function returns one of two values based on a conditional expression.". May be array is not a valid value. Workaround : Sub TestA Dim i as Long, arr, a, b i = 0 a = Array() b = Array(0) arr = b : If i = 0 Then arr = a ' arr = Iif(i = 0, a, b) End Sub
The following line raises an error arr = Iif(True, Array("A","B"), Array("B","A")) ' Raises an error The following line does not work properly: arr = "A" arr = Iif(False, Array("A","B"), Array("B","A")) ' IIF exposes the same issue when with functions returning an Array Sub Main arr = Iif(true, getArray1(), getArray2()) End Sub Function getArray1() As Variant arr = Array("A","B") getArray1 = arr End Function Function getArray2() As Variant arr = Array("B","A") getArray2 = arr End Function