Summary: | Error in the Basic IIf function. | ||
---|---|---|---|
Product: | LibreOffice | Reporter: | Vladimir Sokolinskiy <sokol> |
Component: | BASIC | Assignee: | Not Assigned <libreoffice-bugs> |
Status: | NEW --- | ||
Severity: | normal | CC: | aron.budea, edil, mikekaganski |
Priority: | medium | ||
Version: | 6.0.0.3 release | ||
Hardware: | All | ||
OS: | All | ||
Whiteboard: | |||
Crash report or crash signature: | Regression By: | ||
Bug Depends on: | |||
Bug Blocks: | 127592 |
Description
Vladimir Sokolinskiy
2022-05-18 10:05:33 UTC
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 |