Page 1 of 1

[Solved] BASIC macro button anomaly

Posted: Wed Aug 23, 2023 10:39 pm
by Rotnbair
I recently started learning macro BASIC programming and have written several for a Calc spreadsheet, executed by pushbuttons. I have 2 very similar macros which function as designed; the issue is the different statuses of their pushbuttons on completion. I have attached text files of both.

When the CleanUp macro runs, the final instruction locates the cursor at cell C1 for another round of input; entering data in cell C1 works fine. The Copy30 macro runs fine, same final instruction, but after completion its pushbutton has a dashed-line rectangle superimposed on it---the CleanUp button has no such rectangle. The cursor is again located at cell C1, but if the user attempts to enter data in the cell, pressing the Enter key runs the macro again. To release(?) the button, the user must click on a different cell, not necessary after CleanUp is run. (Neither pushbutton is located in or near the cell C1.)

Obviously I don't understand what makes the 2 buttons different. Any enlightenment would be greatly appreciated. Thanks.

Re: BASIC macro button anomaly

Posted: Wed Aug 23, 2023 11:18 pm
by JeJe
If you post a document with the buttons and code in rather than text files it will make it easier to look at and we can see the whole thing.

Re: BASIC macro button anomaly

Posted: Thu Aug 24, 2023 12:04 am
by Rotnbair
I see your point. I can upload the 100kb file, but the macro code is in My Macros/Standard/Module 1 so it won't be included. I wanted the macros attached to the sheet, since I run it on 2 machines, but when I try to put one in aCalc.ods/Standard/Module 2, the program blows up with "Due to an unexpected error, OpenOffice crashed." This happens every time.

Re: BASIC macro button anomaly

Posted: Thu Aug 24, 2023 12:21 am
by JeJe
You're asking everybody to recreate what you have... create a document, rename the sheets, fill in some data blah blah... before they can look at it... and then guess about buttons.

I've done it (attached with your code) and for me, no crash. No idea what you buttons are or how they connect to it... they're not included.

Re: BASIC macro button anomaly

Posted: Thu Aug 24, 2023 12:23 am
by Rotnbair
I ask the moderator to close this thread.

Re: BASIC macro button anomaly

Posted: Thu Aug 24, 2023 12:25 am
by JeJe
Why do you want that? Have you solved the problem?

Re: BASIC macro button anomaly

Posted: Thu Aug 24, 2023 7:36 am
by Zizi64
Here is JeJe's sample file with two buttons on the first sheet. And the macros are embedded in the file, and assigned to the renamed buttons. Not need to rename the buttons, and not need to rename them to the names of the subroutines, just assign the subs to some Event of the control elements (buttons)

I hahe edited your file in my LibreOffice 7.5.5 therefore the file format maybe has changed to the ODF 1.3 Extended.
Untitled 1_with_Buttons.ods
(12.73 KiB) Downloaded 458 times
Your macros works in my LO 7.5.5 on the JeJe's sample data.
Rotnbair, please upload YOUR sample file here.

Re: [Solved] BASIC macro button anomaly

Posted: Wed Dec 20, 2023 8:27 pm
by Rotnbair
Thanks for the help. I reorganized the macros in the sheet in a major way and the issue disappeared on its own.

By the way, I finally figured out a way to include macros in the Calc spreadsheet document. I had to delete the default library "my macros/standard/module 1" first, then create one in the sheet.

Re: [Solved] BASIC macro button anomaly

Posted: Wed Dec 20, 2023 9:55 pm
by floris v
Rotnbair wrote: Wed Dec 20, 2023 8:27 pm (...) By the way, I finally figured out a way to include macros in the Calc spreadsheet document. I had to delete the default library "my macros/standard/module 1" first, then create one in the sheet.
There is no need to do that. You can save your own macros in the "my macros/standard/module 1" so that they are available for all of your documents as long as you open them on the pc where the macros are saved. If you want to save the macro only in one particular document, just select the item at the bottom of the dialog box, with the Calc document icon, see screenshot.
Schermafdruk van 2023-12-20 20-52-54.png
Schermafdruk van 2023-12-20 20-52-54.png (24.54 KiB) Viewed 2435 times

Re: BASIC macro button anomaly

Posted: Wed Dec 20, 2023 11:29 pm
by Rotnbair
Thanks for the reply.

Ah yes, I did what you suggest for a long time. Since I work on 2 or 3 different machines, it was a pain keeping the macros current on all machines. I could and did create the second module as in your graphic more than once, but then (multiple times, every time) attempting to save a macro to the new spreadsheet module would crash OpenOffice. I have a few Calc spreadsheets, each with its own specific macros, so not having "my macros/standard/module 1" causes me no difficulties and improves portability.

Rather than give up, I decided on the drastic deletion of "my macros/standard/module 1" on a machine, to see if I could then store macros in the spreadsheet module (which worked). I then opened that spreadsheet on a different machine, and both the spreadsheet and OO modules worked fine. But the next time that different machine rebooted, OO reverted to not allowing both modules to contain macros, so I deleted "my macros/standard/module 1" on that one to get to the spreadsheet module macros.

I am open to improvement, so if you can tell what I am doing wrong, I would appreciate the help.
module.png
module.png (16.97 KiB) Viewed 2392 times