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

Macro Question: How can I call a spreadsheet function from..

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Taoism
Guest





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

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.
Back to top
dfrench
Moderator
Moderator


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

PostPosted: Sat Feb 21, 2004 8:32 am    Post subject: Reply with quote

see http://www.oooforum.org/forum/viewtopic.php?p=21960#21960
Back to top
View user's profile Send private message
jimlenn
General User
General User


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

PostPosted: Sat Feb 21, 2004 10:48 am    Post subject: Reply with quote

dfrench:
Your response example uses numbers put directly into the macro. What if you want to put cell addesses in the Array?
Back to top
View user's profile Send private message
dfrench
Moderator
Moderator


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

PostPosted: Sat Feb 21, 2004 12:26 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Taoism
Guest





PostPosted: Mon Feb 23, 2004 1:17 pm    Post subject: Reply with quote

Thanks! That did the trick.

Cheers,
Keith.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API 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