Apache OpenOffice (AOO) Bugzilla – Issue 88491
optional string parameter default value is "0" and ismissing not working
Last modified: 2014-07-24 21:19:08 UTC
When a macro function is called from Calc as formula not all time the "ismissing" on a optional string parameter yield true when missing. and the default value is zero. Steps:- 1. add following list2array macro to "My Macro" module 2. put a break point on "if ismissing(separator) or " .... line 3. come back to Calc to enter formula 4. enter =LIST2ARRAY("aaa,bbb,ccc";;2) 5. press shift+ctrl+enter key to enter as array 6. go to macro editor to debug 7. check * value of separator * value of ismissing(separator) Actual * value of separator = "0" * value of ismissing(separator) = false Expected * value of separator = "" * value of ismissing(separator) = true === list2array macro ==== function list2array( _ optional list as string, _ optional separator as string, _ optional max as integer) if ismissing(list) then list = "" end if if ismissing(separator) or separator = "" or separator = "0" then separator = "," end if dim a() a = split(list, separator) if ismissing(max) then 'nothing elseif max < 1 then 'nothing else redim preserve a(max-1) end if list2array = a end function
Can reproduce it in OOo-Dev_OOO300_m3_en-US on WinXP.
How to perform step 7?
I was about to open a very similar bug report and can provide a simple test case to demonstrate the problem still occurs of OO 4.1.0 VBA allows an optional parameter to be defined as - optional str as string = "abc" - the variable is not initialized to "abc" in OO Alternatively if no default is provided - optional mstr as string mstr - should not be initialized and isMissing(mstr) should return True it actually returns false and mstr is a null string OO works correctly for data type Double and Variant, I have not tested other data types This error is particularly insidious when porting from Excel since no error is raised and differences in function execution may not be readily apparent. I used the following function to show the problem: function TestOpt(optional num as double =123, optional str as string = "abc", optional numv =456, optional strv = "def", optional miss as double, optional mstr as string) as string Dim printstr as string printstr = "num: >>" &num &"<< isMissing " & isMissing(num) printstr = printstr & "; str: >>" &str &"<< isMissing " & isMissing(str) printstr = printstr & "; numv: >>" &numv &"<< isMissing " & isMissing(numv) printstr = printstr & "; strv: >>" &strv &"<< isMissing " & isMissing(strv) rem print printstr printstr = printstr & "; miss: >>" &miss &"<< isMissing " & isMissing(miss) printstr = printstr & "; mstr: >>" &mstr &"<< isMissing " & isMissing(mstr) print printstr TestOpt = printstr end function Output is num: >>123<< isMissing False; str: >><< isMissing False; numv: >>456<< isMissing False; strv: >>def<< isMissing False; miss: >>Error ǀ<< isMissing True; mstr: >><< isMissing False str and mstr are handled incorrectly, other formats are correct
Created attachment 83736 [details] Function to demonstrate problem