[Solved] Calc basic macro not returning values

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
fbicknel
Posts: 7
Joined: Thu Mar 07, 2019 5:00 pm

[Solved] Calc basic macro not returning values

Post by fbicknel »

I have this little function I wrote:

Code: Select all

Function FUNC(x as integer, rn as Array) As Integer
	Dim i as Integer
	Dim FUNC as Integer
	FUNC = 0
	For i = 1 to UBound(rn) step 1
 		FUNC = FUNC + rn(i,1) * x^i
	Next i
End Function
I've stepped through it (breakpoint at line 5) and watched the variables (particularly FUNC), but when it returns, the spreadsheet stubbornly shows zero.

I've even put a FUNC=5 at the end to make SURE something is in FUNC. I've also renamed the thing to other names in case FUNC is a reserved word... I've tried clearing the formatting for the target cells in the spreadsheet. I've tried print()ing the value (I get a nice little pop up with the value of FUNC). Nothing seems to help.

Any ideas? It did work when I was messing with it earlier. It returned values. But somewhere along the bug-fixing way, the thing stopped responding.

OH. I wrote all that, then decided to close up the spreadsheet. This pops up when I try to save the sheet:
Screenshot from 2019-03-07 10-17-55.png
Maybe that's it. How do I fix that? I added

Code: Select all

Sub main
End Sub
to the module and that happied out the save function, but alas I still have the same problem with FUNC above. I guess I shouldn't have deleted main before: first time foibles.
Last edited by Hagar Delest on Sat Mar 09, 2019 6:29 pm, edited 1 time in total.
Reason: tagged solved
- Frank
OpenOffice 7.1.5.2 (or later) on Ubuntu LTS
JeJe
Volunteer
Posts: 2780
Joined: Wed Mar 09, 2016 2:40 pm

Re: Calc basic macro not returning values

Post by JeJe »

You can't declare a variable called Func in a function called Func.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
fbicknel
Posts: 7
Joined: Thu Mar 07, 2019 5:00 pm

Re: Calc basic macro not returning values

Post by fbicknel »

Ah. Guess I /really/ wanted to be sure FUNC was an Integer! :) That was it. Took out the Dim statement and it works.

Many thanks.
- Frank
OpenOffice 7.1.5.2 (or later) on Ubuntu LTS
Post Reply