Ask Your Question
0

How can do function like follows in Libre Office

asked 2015-10-19 15:16:01 +0200

TheoUksi gravatar image

I'm new with this Basic language. I have a Java back round and I can't run the following Function. How do I need to setup it to run in LibreOffice. Apparently Function can not be called inside functions LibreOffice Basic?

REM BASIC

Sub Main

End Sub

Function pPeriod(months, qLed, qHalo, lifeLed, lifeHalo, hoursD, pLed, pHalo, tranFee, ePrice)

For iCount = 0 To months
    newLeds = ROUNDDOWN((iCount*hoursD*30/lifeLed);1)
    newHalos = ROUNDDOWN((iCount*hoursD*30/lifeHalo);1)
    qLed = qLed + newLeds
    qHalo = qHalo + newHalos
    newPriceLeds = qLed*pLed + tranFee + 30*hoursD*ePrice
    newPriceHalos = qHalo*pHalo + tranfee + 30*hoursD*ePrice
    If newPriceLeds > newPriceHalos = True Then Exit For

Print i

End Function

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2015-10-19 23:18:43 +0200

Lupp gravatar image

updated 2015-10-19 23:26:23 +0200

[ROUNDDOWN() is a function of doubtable justification. It actually does not round down the value it got, but rounds down the absolute amount of it and then glues the screwed off sign back to the result.]

In BASIC you will not need a Calc function called via a FunctionAccess object in the above situation but simply a replacement of ROUNDDOWN using a BASIC function doing the same thing if applied to a positive value - as you will have - in the following way:

newLeds = Int((iCount*hoursD*30/lifeLed)*10)/10

[If you actually had negative values and wanted them treated as ROUNDDOWN would do, you had to use the BASIC function 'Fix' instead of 'Int'.]

edit flag offensive delete link more
0

answered 2015-10-19 20:26:28 +0200

Regina gravatar image

For to use Calc functions inside Basic see this answer .

For a general guide to Basic use Andrew Pitonyak: OpenOffice.org Macros Explained.

Your example is missing a Next iCount.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

2 followers

Stats

Asked: 2015-10-19 15:16:01 +0200

Seen: 51 times

Last updated: Oct 19 '15