Bug Hunting Session
Bug 79426 - Macros: Passing an error object to a function causes a run time error.
Summary: Macros: Passing an error object to a function causes a run time error.
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
(earliest affected) release
Hardware: Other All
: low minor
Assignee: Not Assigned
Whiteboard: BSA
Depends on:
Blocks: Macro-StarBasic
  Show dependency treegraph
Reported: 2014-05-29 19:48 UTC by Ewald Anderl
Modified: 2019-09-17 13:14 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:

Writer doc with additional code examples, analysis and screen shots (145.76 KB, application/vnd.oasis.opendocument.text)
2014-05-29 19:48 UTC, Ewald Anderl

Note You need to log in before you can comment on or make changes to this bug.
Description Ewald Anderl 2014-05-29 19:48:22 UTC
Created attachment 100121 [details]
Writer doc with additional code examples, analysis and screen shots

Problem description:
Passing an error object to a function causes a run time error. Any reference within the function to the argument containing an error object such as “CVErr(2)“, causes the run time error: “BASIC runtime error. Argument is not optional.”

How to reproduce the problem:
1. In a LibreOffice document with Macros, open Tools --> Macros --> Organize Macros --> pick any module to edit

2. Type (or cut/paste) the following code in to the “Module” of your choice. (Module1 will do)
Sub TestCVErr
	Dim vErr
	Dim nValue as Integer
	Dim ss
	vErr = CVErr(2)
	nValue = vErr
	ss = ""
	ss = ss & "VarType, TypeName, and nValue = " & VarType(vErr)
	ss = ss & ", " & TypeName(vErr)& ", " & nValue
	Print ss
	Print fnGetErrNum(vErr)	'This causes failure
End Sub

Function fnGetErrNum(vErr)
	Dim nValue as Integer
	nValue = vErr
	fnGetErrNum() = nValue
End Function
3. Run  TestCVErr

4. The program stops with a run time error ( “BASIC runtime error. Argument is not optional.”) in the function

5. Replace the last line in TestCVErr() with the following, passing the integer nValue rather than the error object:
	Print fnGetErrNum(nValue)	'This works
6. Run TestCVErr and the function returns the number correctly.

Current behavior:
If the argument being passed to the function contains an error object, any reference to it will cause a run time error. The same code that works in the main routine will fail if placed within a function referencing the vErr as an argument. The same behavior was observed in both a Linux (fc20) and a Windows (Win7/64-Bit) environment.

Expected behavior:
The function should return an integer value of 2; this should be the same behavior as the code in the  main routine “nValue = vErr” which casts the error object into an integer value.

Operating System: All
Version: release
Comment 1 Joel Madero 2015-02-25 23:30:41 UTC
ubuntu 14.10 x64
LibreOffice rc

Marking as:
Minor - workaround exists, does not prevent high quality work. If there is no workaround then I suppose "normal" would be the appropriate - not major.

low - incredibly low chance of this affecting many users at all. Nearly a year later, no dupes, no additional comments, etc...

CC'ing Noel to get his opinion.
Comment 2 tommy27 2016-04-16 07:27:26 UTC Comment hidden (obsolete)
Comment 3 QA Administrators 2017-05-22 13:24:20 UTC Comment hidden (obsolete)
Comment 4 Buovjaga 2019-08-11 11:23:13 UTC
Still repro with file

Version: (x86)
Build ID: c738be4de6886a0c96b7d10df7e78c8b2964c135
CPU threads: 4; OS: Windows 10.0; UI render: default; VCL: win; 
Locale: fi-FI (fi_FI); UI-Language: en-US
Calc: threaded