Apache OpenOffice (AOO) Bugzilla – Issue 65555
Basic function does not accept variants
Last modified: 2017-05-20 11:29:57 UTC
The following fails at last step because Date2ISO insists on getting an object. Surprisingly boolean TestStruct(v) works fine: Sub Main Dim oDt as new com.sun.star.util.Date oDt.Year = 2000 oDt.Month = 12 oDt.Day =31 print TestStruct(oDt) print TestStruct(0) print IsoFromDateStruct(oDt) print IsoFromDateValue(39000) print Date2ISO(oDt) print Date2ISO(39000) End Sub Function TestStruct(v)as boolean Dim bResult as Boolean If isUnoStruct(v) then bResult= true Else bResult = false EndIf TestStruct = bResult End Function Function Date2ISO(vDt) as String 'conversion to basic-date dtVal If isUnoStruct(vDt)Then 'object/UNO-struct dtVal = dateSerial(vDt.year,vDt.month,vDt.day) Else dtVal = cDate(vDt) End If sDt = cDateToISO(cDate(dtVal)) Date2ISO = left(sDt,4)&"-"& mid(sDt,5,2)&"-"& right(sDt,2) End Function 'pass a number or date-string Function IsoFromDateValue(vDt)as string Dim sDt$ sDt = cDateToISO(cDate(vDt)) IsoFromDateValue = left(sDt,4)&"-"& mid(sDt,5,2)&"-"& right(sDt,2) End Function 'pass an UNO-struct com.sun.star.util.Date or DateTime. Function IsoFromDateStruct(oDt as Object)as string Dim dtVal as Date If isUNOStruct(oDt) then dtVal = DateSerial(oDt.Year,oDt.Month,oDt.Day) IsoFromDateStruct = IsoFromDateValue(dtVal) endif End Function
Sorry, I can't find any attached patch file so I change the type to "defect". Andreas, I send this issue to you but it still needs confirmation.
Problem: Using vDt as object in If isUnoStruct(vDt)Then 'object/UNO-struct dtVal = dateSerial(vDt.year,vDt.month,vDt.day) Else ... makes the compiler believe the symbol vDt is an object in any case. This is wrong and leads to very confusing errors -> P3, 2.x, STARTED
-> OOo 2.1
According to discussion with mba/kso -> 2.2 as cws ab30 has to be integrated very soon.
2.x due to limited resources. Has to be evaluated and targeted together with all other 2.x tasks.
basic and scripting issues now should be assigned to component "scripting"
set target to 3.x according to http://wiki.services.openoffice.org/wiki/Target_3x
Because an unhappy user cited this bug on the dev ml, I comment that this antique bug has a simple workaround, entirely thanks to ab's insightful analysis. If the parser is messing up, give it a different variable to mess up on (and don't use that again). The following version of function Date2ISO appears to run correctly; the original version produces a run-time error. Function Date2ISO(vDt) as String 'conversion to basic-date dtVal If isUnoStruct(vDt)Then 'object/UNO-struct ' dtVal = dateSerial(vDt.year,vDt.month,vDt.day) vW = vDt 'work around compiler bug 65555 dtVal = dateSerial(vW.year,vW.month,vW.day) Else dtVal = cDate(vDt) End If sDt = cDateToISO(cDate(dtVal)) Date2ISO = left(sDt,4)&"-"& mid(sDt,5,2)&"-"& right(sDt,2) End Function
Reset assigne to the default "issues@openoffice.apache.org".