# How can do function like follows in Libre Office [closed]

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 reopen merge delete

### Closed for the following reason question is not relevant or outdated by Alex Kemp close date 2020-08-26 21:54:39.214481

Sort by » oldest newest most voted

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.

more

[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'.]

more