OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Creating own functions - programmers guide

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc
View previous topic :: View next topic  
Author Message
chrizio
General User
General User


Joined: 11 Apr 2006
Posts: 21

PostPosted: Fri Sep 29, 2006 11:26 am    Post subject: Creating own functions - programmers guide Reply with quote

Hi,

I didn't manage to find on the OOo portal any good guide
about creating / programming own Calc functions.
I have to write some functions to be used in my Calc sheet.
Where can I study the underlying programming language ?

My current question on writing user defined functions is following:
The function shall take some number of cells containing one integer
pro cell as an array - input parameter.
How must be such function be defined ?
Back to top
View user's profile Send private message
chrizio
General User
General User


Joined: 11 Apr 2006
Posts: 21

PostPosted: Fri Sep 29, 2006 12:31 pm    Post subject: Reply with quote

Calc is someway strange.

Why does following function

FUNCTION aaa(ByVal x As INTEGER) As INTEGER
DIM s%
s=x
return s
End Function

generate compiling error as below ?
"Basic syntax error - label s undefined" <- message translated from German

The function is placed in My Macros->Standard->xxxx
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10106
Location: Germany

PostPosted: Fri Sep 29, 2006 1:53 pm    Post subject: Reply with quote

The StarBasic language is fairly documented in the online-help. You may use other languages like java, python, C++, C#, Jscript.
Developer's guide:
http://api.openoffice.org/docs/DevelopersGuide/DevelopersGuide.xhtml
API reference:
http://api.openoffice.org/docs/common/ref/com/sun/star/module-ix.html
The appropriate forums on this site:
http://www.oooforum.org/forum/viewforum.phtml?f=9
http://www.oooforum.org/forum/viewforum.phtml?f=11
Short answer:
A sheet-cell function passes and returns strings, doubles or errors.
The basic language has an undocumented keyword "return", but I do not know what it's good for. The return-value of a Basic-function has to be assigned to the function's name:
Code:

Function testParam(v)
If typeName(v) = "Double" then
   testParam=  cInt(v)
else
   ' return error #VALUE
   testParam=  Null
endif

_________________
Rest in peace, oooforum.org
Get help on https://forum.openoffice.org
Back to top
View user's profile Send private message
noranthon
Super User
Super User


Joined: 07 Jul 2005
Posts: 3318

PostPosted: Fri Sep 29, 2006 9:31 pm    Post subject: Reply with quote

I use "return" in conjunction with GoSub.

Other values are mentioned in the API index R but none seem relevant here.
_________________
search forum by month
Back to top
View user's profile Send private message
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Sat Sep 30, 2006 8:08 am    Post subject: Reply with quote

You return the value of a function by setting the function name = value so try
aaa = s
instead of
return s.
Back to top
View user's profile Send private message
chrizio
General User
General User


Joined: 11 Apr 2006
Posts: 21

PostPosted: Sat Sep 30, 2006 8:19 am    Post subject: Reply with quote

Thanks for all answers.

That with return xxxx I have found just in forum or in help.
It wasn't my own invention.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group