| View previous topic :: View next topic |
| 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. |
|
| Back to top |
|
 |
dfrench Moderator

Joined: 03 Mar 2003 Posts: 1605 Location: Wellington, New Zealand
|
|
| Back to top |
|
 |
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? |
|
| Back to top |
|
 |
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. |
|
| Back to top |
|
 |
Taoism Guest
|
Posted: Mon Feb 23, 2004 1:17 pm Post subject: |
|
|
Thanks! That did the trick.
Cheers,
Keith. |
|
| Back to top |
|
 |
|
|
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
|