[Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register]

Author Message
Taoism
Guest

Posted: Sat Feb 21, 2004 8:19 am    Post subject: Macro Question: How can I call a spreadsheet function from..

Hi all,

How can I call a spreadsheet function from within a user-made function?

For example, I can use =max(0,-12) in the spreadsheet.

but how can I call the max function in a user-made function?

i.e. (look at the end of the card_balance_x function)
 Code: function  min_pymt_x(prior_bal as single, min_pymt_pct as single)        min_pymt_x =  prior_bal * min_pymt_pct    end function    function interest_x(prior_bal as single, card_pct as single)       interest_x = prior_bal * card_pct * (1/12)    end function        function card_balance_x(prior_bal as single, card_pct as single, min_pymt_pct as single, optional extra_pymnt as single)       if IsMissing(extra_pymnt) then          extra_pymnt = 0       end if       s = min_pymt_x(prior_bal, min_pymt_pct)       r = interest_x(prior_bal, card_pct)              bal = prior_bal + CSng(r) - CSng(s) - extra_pymnt       'I want to use max(0,bal) instead of iif       'so, how can I call it?       card_balance_x =iif(bal < 0, 0, bal)    end function

Thanks in advance for any replies!

Cheers,
Keith.
dfrench
Moderator

Joined: 03 Mar 2003
Posts: 1605
Location: Wellington, New Zealand

 Posted: Sat Feb 21, 2004 8:32 am    Post subject:
jimlenn
General User

Joined: 01 Apr 2003
Posts: 39
Location: The cold, windswept, and great, upper Great Plains, USA.

 Posted: Sat Feb 21, 2004 10:48 am    Post subject: dfrench: Your response example uses numbers put directly into the macro. What if you want to put cell addesses in the Array?
dfrench
Moderator

Joined: 03 Mar 2003
Posts: 1605
Location: Wellington, New Zealand

 Posted: Sat Feb 21, 2004 12:26 pm    Post subject: You have to put whatever the function expects into the array. If you want to use com.sun.star.sheet.FunctionAccess , and the function expects a data array rather than an array of ranges get the data from the ranges into an array through getdataarray(). There are a limited number of functions that are supported by com.sun.star.sheet.GeneralFunction.XXXX like SUM and MAX and these operate on a group of ranges.
Taoism
Guest

 Posted: Mon Feb 23, 2004 1:17 pm    Post subject: Thanks! That did the trick. Cheers, Keith.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT - 8 Hours Page 1 of 1

 Jump to: Select a forum OpenOffice.org Forums----------------Setup and TroubleshootingOpenOffice.org WriterOpenOffice.org CalcOpenOffice.org ImpressOpenOffice.org DrawOpenOffice.org MathOpenOffice.org BaseOpenOffice.org Macros and APIOpenOffice.org Code Snippets Community Forums----------------General DiscussionSite Feedback
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