[Solved] Call macro function from Calc with parameter and return value

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Locked
pommie
Posts: 8
Joined: Fri Sep 29, 2023 3:43 am

[Solved] Call macro function from Calc with parameter and return value

Post by pommie »

I've searched everywhere for this and can't find it.

What I've tried,
macro.png
macro.png (56.14 KiB) Viewed 14262 times
Image now added thanks to FJCC

Thanks.

Edit, forgot to add, if I cange A1(hello world) it says Label dat undefined!!
Last edited by MrProgrammer on Fri Sep 29, 2023 4:41 pm, edited 6 times in total.
Reason: Moved to macro forum
LibreOffice V7.3.7.2 on Linux Mint V21.2
FJCC
Moderator
Posts: 9555
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: How to call a macro function with a parameter and return a value?

Post by FJCC »

To upload an image, click Post Reply and look for the Attachments tab just below the box where you type a response.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
Posts: 9555
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: How to call a macro function with a parameter and return a value?

Post by FJCC »

You return a value by passing the return value to the function name.

Code: Select all

Function myConvert(dat as variant) as variant
myConvert = dat
end Function
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
User avatar
karolus
Volunteer
Posts: 1228
Joined: Sat Jul 02, 2011 9:47 am

Re: [Solved] How to call a macro function with a parameter and return a value?

Post by karolus »

@pommie:
crosspost WITHOUT reference is RUDE!

https://ask.libreoffice.org/t/solved-ru ... c/96437/14
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 24.8… flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
User avatar
robleyd
Moderator
Posts: 5404
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: [Solved] How to call a macro function with a parameter and return a value?

Post by robleyd »

To elaborate on @karolus comment:- If you cross post, please let us know that you have done so, otherwise it leads to several discussions and a waste of time because several identical answers may be posted by different users.
Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 25.2.5.2; SlackBuild for 25.2.5 by Eric Hameleers
---------------------
Roses are Red, Violets are Blue]
Unexpected '{' on line 32
.
User avatar
MrProgrammer
Moderator
Posts: 5309
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: [Solved] Call macro function from Calc with parameter and return value

Post by MrProgrammer »

pommie wrote: Fri Sep 29, 2023 3:57 am How to call a macro function with a parameter and return a value?
Example: [Calc] Pass array values to/from a Basic function

pommie wrote: Fri Sep 29, 2023 3:57 am I've searched everywhere for this and can't find it.
Passing arguments to a macro

pommie wrote: Fri Sep 29, 2023 3:57 am it says Label dat undefined
Your attempt failed because in Basic the Return statement is used with GoSub, not to exit a function. The language has worked this way for 60 years.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.6, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
pommie
Posts: 8
Joined: Fri Sep 29, 2023 3:43 am

Re: [Solved] Call macro function from Calc with parameter and return value

Post by pommie »

The language has worked this way for 60 years.
Yes, I know that. However, the error "dat undefined" is simply wrong and sent me in the wrong direction. "Syntax error" would have given me a clue.
LibreOffice V7.3.7.2 on Linux Mint V21.2
pommie
Posts: 8
Joined: Fri Sep 29, 2023 3:43 am

Re: [Solved] How to call a macro function with a parameter and return a value?

Post by pommie »

karolus wrote: Fri Sep 29, 2023 9:11 am @pommie:
crosspost WITHOUT reference is RUDE!

https://ask.libreoffice.org/t/solved-ru ... c/96437/14
If you care to explain what that means I'll attempt to not be RUDE in future.

Howevere, I consider your post (without explaination) to be RUDE. Kinda armchair warrior RUDE.
LibreOffice V7.3.7.2 on Linux Mint V21.2
FJCC
Moderator
Posts: 9555
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: [Solved] Call macro function from Calc with parameter and return value

Post by FJCC »

"Cross post" means posting the same question on different forums, mail lists or other help sites. It can waste the time of people trying to help because they may be unaware that the problem has already been solved on another site.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
User avatar
karolus
Volunteer
Posts: 1228
Joined: Sat Jul 02, 2011 9:47 am

Re: [Solved] How to call a macro function with a parameter and return a value?

Post by karolus »

pommie wrote: Fri Sep 29, 2023 6:56 pm
If you care to explain what that means I'll attempt to not be RUDE in future.

Howevere, I consider your post (without explaination) to be RUDE. Kinda armchair warrior RUDE.
If you ask the same question in more than one place in the future, please be kind enough to link to the other topic.
Thank You!!
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 24.8… flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
pommie
Posts: 8
Joined: Fri Sep 29, 2023 3:43 am

Re: [Solved] How to call a macro function with a parameter and return a value?

Post by pommie »

robleyd wrote: Fri Sep 29, 2023 11:06 am To elaborate on @karolus comment:- If you cross post, please let us know that you have done so, otherwise it leads to several discussions and a waste of time because several identical answers may be posted by different users.
Only just saw your post. Thanks for the explaination. But I still don't know what "cross post" means.
LibreOffice V7.3.7.2 on Linux Mint V21.2
User avatar
karolus
Volunteer
Posts: 1228
Joined: Sat Jul 02, 2011 9:47 am

Re: [Solved] Call macro function from Calc with parameter and return value

Post by karolus »

AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 24.8… flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
pommie
Posts: 8
Joined: Fri Sep 29, 2023 3:43 am

Re: [Solved] Call macro function from Calc with parameter and return value

Post by pommie »

What is it with you? Are you the local bully? "We only wear pink on Tuesdays" so lets make fun of the new guy.

I didn't know the rules!!!!!!!

As I explained in another thread (google it) I thought OpenOffice and LibreOffice were the same and when I found out they weren't and I'd posted my question in the wrong forum I looked for the correct forum and postred it there. But it seems that's worng and I'm RUDE.

I know who I think is RUDE.
LibreOffice V7.3.7.2 on Linux Mint V21.2
User avatar
robleyd
Moderator
Posts: 5404
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: [Solved] Call macro function from Calc with parameter and return value

Post by robleyd »

I'd posted my question in the wrong forum
Not sure how you define wrong but you'll find in the header of each page here
User community support forum for Apache OpenOffice, LibreOffice and all the OpenOffice.org derivatives
AskLO is dedicated to LibreOffice, however.
I didn't know the rules!!!!!!!
May I recommend for you the Survival Guide.
Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 25.2.5.2; SlackBuild for 25.2.5 by Eric Hameleers
---------------------
Roses are Red, Violets are Blue]
Unexpected '{' on line 32
.
User avatar
MrProgrammer
Moderator
Posts: 5309
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: [Solved] Call macro function from Calc with parameter and return value

Post by MrProgrammer »

pommie wrote: Fri Sep 29, 2023 10:53 pm I didn't know the rules!!!!!!!
You're new to this forum. It seems to me that your fundamental problem was posting without reading the Survival Guide. There you would have found links to several sources which might have solved your problem without the need to ask a question here. We have a whole forum devoted to OpenOffice Basic, Python, BeanShell, JavaScript and a search there for Calc and parameters should have found topics with examples for you which would show how to return a function result. We also have the Code Snippets forum.

You would have learned in the Survival Guide that multi-posting (asking the same question more than once here) and cross-posting (asking the same question here and elsewhere without providing links) are frowned upon. You would have learned how to upload an attachment. Please study the Survival Guide before posting again.

When you upload a picture of your program, instead of the actual program, anyone who wants to test must retype it. This discourages people from helping. The situation is similiar with people who upload pictures of a spreadsheet instead of the spreadsheet itself. The picture hides the actual cell values, formulas, cell formats, conditional formatting, often the row/column headings so we can't tell the cell address, and other important information which may be key to solving the problem. And anyone who wants to test would need to retype your data. You don't want to put that roadblock in front of them. I hardly ever offer to help based on a picture of a spreadsheet.

Let me clarify a bit about this forum versus Ask LibreOffice. The latter says: This site is not a forum here, but a questions / answers site. I don't use Ask LibreOffice so I'm not sure exactly what that means, but discussion has suggested to me that the Ask LibreOffice answers to a question are independent of each other and it is harder to understand the solution. Our forum does accept questions from LibreOffice users. There is a lot of similarity in OpenOffice/LibreOffice usage, this forum is perhaps easier to use, and we have a long history of topics which would apply to LibreOffice. It is important for us to know that you use LibreOffice, but your forum signature provides that information.

If, in addition to being new to this forum, you are new to web forums in general, the following link has valuable advice for using them effectively:
How To Ask Questions The Smart Way

pommie wrote: Fri Sep 29, 2023 10:53 pm As I explained in another thread (google it) I thought OpenOffice and LibreOffice were the same and when I found out they weren't and I'd posted my question in the wrong forum I looked for the correct forum and [posted] it there.
This is understandable and would have been OK if you had just said in this topic that you were seeking help elsewhere and there was no need to respond. It would have been more helpful to provide a link to your other topic instead of telling people to search for it, which comes across poorly when you're asking for free help with your problem. The impression you make matters. The link above explains this in more detail.

pommie wrote: Fri Sep 29, 2023 6:51 pm However, the error "dat undefined" is simply wrong and sent me in the wrong direction. "Syntax error" would have given me a clue.
I found the unexpected Label dat undefined error to be quite interesting, suggesting that the syntax was correct and the real problem was that your program had no dat: label. This proves to be the case. Although the Return instruction documentation shows that there are no operands allowed, tests show that Return does, in fact, accept a label. The effect is that the instruction ends the GoSub, but instead of returning control to the instruction after GoSub, control is returned to the specified label! Perhaps this was done to provide compatibility with another Basic dialect which includes this contsruct. No one is going to revise the documentation to show that a label is allowed since GoSub/Return is deprecated by Call and Sub/End Sub, which are more useful.

In the following program if the Bar: label is removed a label undefined error is reported.
Sub T110577
Rem Should show 1,2,3
Rem Changing 'Return Bar' to 'Return' shows 1,2,4
MsgBox 1 : GoSub Foo : MsgBox 4 : Exit Sub
Foo: MsgBox 2 : Return Bar
MsgBox 0
Bar: MsgBox 3
End Sub
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.6, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
Locked