Ask Your Question

Problem creating user-defined function in LibreCalc [closed]

asked 2013-06-24 17:47:19 +0100

neolith gravatar image

updated 2013-06-25 02:38:56 +0100

oweng gravatar image

I am trying to create the following function:

Function IMPARA (x,y)
End Function

When I call the function in the spreadsheet as =IMPARA(A1,B2), I get the following error: BASIC runtime error. Sub-procedure or function procedure not defined.

What am I doing wrong?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2015-11-02 23:27:18.731479


Can you use Calc functions in BASIC? It sounds like it may be unhappy with the IMDIV(), IMPRODUCT(), and IMSUM() functions as being 'not defined'.

oweng gravatar imageoweng ( 2013-06-25 03:23:15 +0100 )edit

I think you are right. Complex numbers are actually strings, so I guess I will have to parse the arguments into real and imaginery parts, convert to numbers and do the math and then re-create the string. PITA.

neolith gravatar imageneolith ( 2013-06-25 04:55:20 +0100 )edit

Depends on operating system. Under windows, "Function Function_Name()" is enough. But under Ubuntu, you must declare the function properly, such "Function Function_Name() as Var_Type". If your function returning number, use Double data type for output.

Paijo gravatar imagePaijo ( 2013-06-25 08:24:54 +0100 )edit

@Paijo setting IMPARA (x as string, y as string) as Var_Type does not alter the error. I am not sure you can use Calc functions (e.g., SUM) in a user-defined function. As @neolith says, for complex numbers (e.g., "-10+8i") this makes it a real pain. @neolith please report your results back here, regardless of whether you get it working or not.

oweng gravatar imageoweng ( 2013-06-25 13:27:19 +0100 )edit

@oweng I just try to create a user-defined function use calc function nama. I make a RAND() function that always return value 100. Calc function always executed, and the macro never executed. So, back to main problem, I agree with you that the source of error are undefined function/procedure.

Paijo gravatar imagePaijo ( 2013-06-26 11:58:48 +0100 )edit

3 Answers

Sort by » oldest newest most voted

answered 2013-06-27 02:21:24 +0100

w_whalley gravatar image

You can call calc functions in basic, but the arguments need to be passed as an array. See this link

I think this function may work--give it a try and confirm.

function impara(x,y)
end function
edit flag offensive delete link more


Thanks, works perfectly.

neolith gravatar imageneolith ( 2013-06-27 02:50:00 +0100 )edit

answered 2013-06-27 01:30:37 +0100

oweng gravatar image

I am going to move some of the content from the above comments into an answer in order to provide a possible resolution for this question.

I don't think you can you use Calc functions in BASIC. Even changing the first line to:

IMPARA (x as string, y as string) as Var_Type the same error. It sounds like it is unhappy with the IMDIV(), IMPRODUCT(), and IMSUM() functions as being 'not defined'. Complex numbers (e.g., "-10+8i") are treated as strings, so the function needs to parse the arguments into real and imaginary parts, convert these parts to numbers, do the math, and then re-create the string (answer) to be returned.

edit flag offensive delete link more

answered 2013-06-27 02:23:54 +0100

m.a.riosv gravatar image

A good place to find useful information:

Here the information on page 513 from Pitonyak guide.

**15.10. Accessing Calc functions**  
You can call Calc functions from a macro.  
Listing 455. Call the MIN function directly.  

Sub callFunction  
Dim oFA  
oFA = createUnoService( "" )  
' Calculate min of numbers.  
print oFA.callFunction( "MIN", array( 10, 23, 5, 345 ) )  
End Sub
edit flag offensive delete link more

Question Tools


Asked: 2013-06-24 17:47:19 +0100

Seen: 3,933 times

Last updated: Jun 27 '13