Issue 88491 - optional string parameter default value is "0" and ismissing not working
Summary: optional string parameter default value is "0" and ismissing not working
Alias: None
Product: Calc
Classification: Application
Component: programming (show other issues)
Version: OOo 2.4.0
Hardware: All All
: P3 Trivial (vote)
Target Milestone: ---
Assignee: AOO issues mailing list
QA Contact:
Keywords: needhelp
Depends on:
Reported: 2008-04-20 16:34 UTC by bijugc
Modified: 2014-07-24 21:19 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---

Function to demonstrate problem (9.96 KB, application/vnd.oasis.opendocument.spreadsheet)
2014-07-24 21:19 UTC, Bob
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
Description bijugc 2008-04-20 16:34:28 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.

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) 

   * value of separator             = "0"
   * value of ismissing(separator)  = false

   * 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
  elseif max < 1 then
    redim preserve a(max-1)
  end if 
  list2array = a
end function
Comment 1 amy2008 2008-08-21 07:25:07 UTC
Can reproduce it in OOo-Dev_OOO300_m3_en-US on WinXP.
Comment 2 Edwin Sharp 2014-01-08 08:54:41 UTC
How to perform step 7?
Comment 3 Bob 2014-07-24 21:17:33 UTC
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
Comment 4 Bob 2014-07-24 21:19:08 UTC
Created attachment 83736 [details]
Function to demonstrate problem