[Solved] How to return #VALUE! code from Basic function?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
v_mil
Posts: 7
Joined: Mon Oct 24, 2011 8:20 pm
Location: Kyiv, Ukraine

[Solved] How to return #VALUE! code from Basic function?

Post by v_mil »

Hello!

How to return error codes (#VALUE!, #NUM! etc) from Basic functions without showing any error message box?
My functions may return any value from -inf to inf, so it's impossible to use any number as error identifier.
A sheet calculates this function many thousand times, so message boxes after any mistake in input data may freeze a calculation process for a days.
I try a statement <FuncName>=Null:Exit Function, where <FuncName> is the name of my function. If a cell contains the formula "=<FuncName>()" the result is a BLANK CELL without any text or value. The formula "=<FuncName>()+0" produces desired "#VALUE!". But I can't find this possibility in any documentation. So, I afraid of using incorrect library behavior bug. Future updates will change this behavior and my sheet shell produce wrong results.

Please, help me!
Last edited by v_mil on Thu Oct 27, 2011 8:39 am, edited 1 time in total.
LibreOffice 3.4.4 on Ubuntu 11.04
User avatar
Villeroy
Volunteer
Posts: 31286
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How to return #VALUE! code from Basic function?

Post by Villeroy »

Return Basic value Null.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
v_mil
Posts: 7
Joined: Mon Oct 24, 2011 8:20 pm
Location: Kyiv, Ukraine

Re: How to return #VALUE! code from Basic function?

Post by v_mil »

Many thanks for your answer!
So, as I understand, returning Null is a standard action to silent error return in OOo Basic.
But why I see nothing in the destination cell of my sheet if the function returns Null???
I use the workaround described in A3 cell of example below. If it is correct, I ready to set [SOLVED] status

Example: MyFunction() returns null:

Cell Formula Result
A1 =MyFunction() Absolutely nothing!!! Why???
A2 =A1+1 #VALUE!
A3 =MyFunction()+0 #VALUE!
LibreOffice 3.4.4 on Ubuntu 11.04
User avatar
Villeroy
Volunteer
Posts: 31286
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How to return #VALUE! code from Basic function?

Post by Villeroy »

v_mil wrote:But why I see nothing in the destination cell of my sheet if the function returns Null???
Because your function does not return Null.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
v_mil
Posts: 7
Joined: Mon Oct 24, 2011 8:20 pm
Location: Kyiv, Ukraine

Re: How to return #VALUE! code from Basic function?

Post by v_mil »

I'm sorry. But what's wrong???
My test function is:

function MyFunction()
MyFunction=Null
end function
LibreOffice 3.4.4 on Ubuntu 11.04
User avatar
Villeroy
Volunteer
Posts: 31286
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How to return #VALUE! code from Basic function?

Post by Villeroy »

Something has changed. In older versions Basic Null used to yield #VALUE. Now we see an empty string as function result.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
v_mil
Posts: 7
Joined: Mon Oct 24, 2011 8:20 pm
Location: Kyiv, Ukraine

Re: How to return #VALUE! code from Basic function?

Post by v_mil »

Hi!
So, the easiest way to obtain #Value is return Null or "" and use in cell
=<Function Name>(<Argument List)+0.
Many thanks!
LibreOffice 3.4.4 on Ubuntu 11.04
Post Reply