[Solved] Calc basic macro not returning values

Creating a macro - Writing a Script - Using the API

[Solved] Calc basic macro not returning values

Postby fbicknel » Thu Mar 07, 2019 5:26 pm

I have this little function I wrote:

Code: Select all   Expand viewCollapse view
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   Expand viewCollapse view
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 6.1.5.2 on Ubuntu LTS
fbicknel
 
Posts: 2
Joined: Thu Mar 07, 2019 5:00 pm

Re: Calc basic macro not returning values

Postby JeJe » Thu Mar 07, 2019 11:17 pm

You can't declare a variable called Func in a function called Func.
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 513
Joined: Wed Mar 09, 2016 2:40 pm

Re: Calc basic macro not returning values

Postby fbicknel » Sat Mar 09, 2019 5:50 pm

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 6.1.5.2 on Ubuntu LTS
fbicknel
 
Posts: 2
Joined: Thu Mar 07, 2019 5:00 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 14 guests