[Solved] Random error messages with 28000 line macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Crisdeannn
Posts: 10
Joined: Mon Nov 27, 2017 7:47 pm

[Solved] Random error messages with 28000 line macro

Post by Crisdeannn »

Hello,

For few days I struggle with strange behaviour of the editor.

Probably it started since I had downloaded additional dialog window from another spreadsheet and made few changes in the sequence of first functions in the code.

When I start a macro, it breaks and I am getting random and pointless error notifications.

For example:

for line:
dim oWindow as object
"Inadmissible value or data type.
Index out of defined range."

for line
oSheet = ThisComponent.Sheets(4)
"BASIC runtime error.
Object variable not set."

for line:
if parameter = 0 then
"BASIC runtime error.
Object variable not set."

etc.

Sometimes all I need to do to solve that issue is to close and open the spreadsheet or to place a line with MsgBox() function before the line which was a subject of an "error", for example:

MsgBox("Hello")
dim oWindow as object

Such "solution" works for a while but soon these issues return in different code line.

Since I don't even know how to define the problem, I could not find any solutions, but it looks like a general issue that should have happened to other users by now. Do you have any suggestions ?

Thank you
Last edited by Crisdeannn on Sat Apr 30, 2022 7:12 am, edited 1 time in total.
LibreOffice 7.0.4.2 (x64), Windows 10
User avatar
RoryOF
Moderator
Posts: 34610
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Random error messages

Post by RoryOF »

I think we need to see the full text of the macro.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
JeJe
Volunteer
Posts: 2777
Joined: Wed Mar 09, 2016 2:40 pm

Re: Random error messages

Post by JeJe »

Try a search for all the other instances of the variables you're having problems with to see if there are any conflicts/duplications. If you have a function or another variable also called oWindow you can have problems. It could be in an extension or it could be in the built in OO macro libraries.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2777
Joined: Wed Mar 09, 2016 2:40 pm

Re: Random error messages

Post by JeJe »

Or just try changing the names to something less generic.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Crisdeannn
Posts: 10
Joined: Mon Nov 27, 2017 7:47 pm

Re: Random error messages

Post by Crisdeannn »

RoryOF wrote:I think we need to see the full text of the macro.
The macro has more than 28.000 lines and, unfortunately, I am not allowed to publish the whole code. It is also impossible to choose problematic parts, because error messages seems to appear randomly in unpredictable parts of the code. I suppose that studying it would not lead to the answer...
JeJe wrote:Try a search for all the other instances of the variables you're having problems with to see if there are any conflicts/duplications. If you have a function or another variable also called oWindow you can have problems. It could be in an extension or it could be in the built in OO macro libraries.
JeJe wrote:Or just try changing the names to something less generic.
All variable and function names are uniqe. They worked fine before I made a change that caused the problem. I think the code and variable names are not the issue.

To give you better understanding of what is going on, I'll describe what I did in last minutes and how I "solved" the problem.

I was trying to shorten the code to recreate these errors on short code version. I removed first two functions (which were not important) and the macro started without any error notifications. After pressing one of the keys in dialog window it broke again with another issue:

for line:
z=2
"BASIC runtime error.
Object variable not set."

Before z=2, I just added "dim z as integer" and restrated the macro. Now it didn't even start (so the situation got worse) but broke on a line of different routine:

for line:
if parametry_pierwotne = 0 then
"BASIC runtime error.
Object variable not set."

Before this line I added empty line (just by simply pressing enter) and restarted macro again. Now it works fine and do not crush. Everything seems to be perfect.

When changing the code I was also getting error messages like:

for line:
MsgBox("Start")
"BASIC runtime error.
Sub-procedure or function procedure not defined."

or for line:
Start_dialog_0
"BASIC runtime error.
Property or method not found: ᤀ禁€ऀ." (yes, with these funny characters)

As you can see these errors seem to make no sense. I wonder what can cause the program to behave like that.
LibreOffice 7.0.4.2 (x64), Windows 10
User avatar
RoryOF
Moderator
Posts: 34610
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Random error messages

Post by RoryOF »

It is my memory (perhaps faulty) that there is a limit of 64KB to an OpenOffice macro code module - perhaps also to a LibreOffice macro code module. If you have 28,000+ lines, that only allows 2.5 characters per line. So if my memory is correct (not checked) you may need to break your code into modules. But I am not an expert macro writer, so someone with more experience may have other suggestions to offer.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Crisdeannn
Posts: 10
Joined: Mon Nov 27, 2017 7:47 pm

Re: Random error messages

Post by Crisdeannn »

RoryOF wrote:It is my memory (perhaps faulty) that there is a limit of 64KB to an OpenOffice macro code module - perhaps also to a LibreOffice macro code module. If you have 28,000+ lines, that only allows 2.5 characters per line. So if my memory is correct (not checked) you may need to break your code into modules. But I am not an expert macro writer, so someone with more experience may have other suggestions to offer.
Considering what errors I get, that could be the reason. I have checked that and OpenOffice wiki states that modules within libraries have a maximum size of 64kb.

I have it in one module and the code contains 620.000 characters (665 kB in notepad).

However, I have experienced this problem just for few days. Last week macro versions have over 600.000 characters, which means that they exceed 64kb limit 10 times and still work fine.

I will try to split the code in few modules and let you know if the problem reoccur.
LibreOffice 7.0.4.2 (x64), Windows 10
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Random error messages

Post by Villeroy »

The macro has more than 28.000 lines
And why do you need any help from us? You are the expert. You have the code.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Crisdeannn
Posts: 10
Joined: Mon Nov 27, 2017 7:47 pm

Re: [Solved] Random error messages

Post by Crisdeannn »

RoryOF wrote:It is my memory (perhaps faulty) that there is a limit of 64KB to an OpenOffice macro code module - perhaps also to a LibreOffice macro code module. If you have 28,000+ lines, that only allows 2.5 characters per line. So if my memory is correct (not checked) you may need to break your code into modules. But I am not an expert macro writer, so someone with more experience may have other suggestions to offer.
It took me some time to confirm that the solution is robust. Breaking the code into modules solves this kind of problem entirely.

Thank you for your support.
LibreOffice 7.0.4.2 (x64), Windows 10
nickGiard
Posts: 16
Joined: Fri Nov 10, 2017 5:57 pm

Re: [Solved] Random error messages with 28000 line macro

Post by nickGiard »

I am stunned to think macros all in one module for 28000 rows. The modules create a namespaces, so you can call function with same name : module1.funct e module2.funct, example Sub Main() is in every module.
The namespace is no abstract, but represent a logical set of functions. A module can represents a Class, where the properties are in a Type and the functions (methods) have an instance of the Type for parameter.
I think this as an architectural design for the own project.
LibreOffice 6.3 on Windows 10 64bit
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: [Solved] Random error messages with 28000 line macro

Post by John_Ha »

28000 lines of linear code is a disaster waiting to happen ... and it has happened.

Break it into manageable modules.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
User avatar
karolus
Volunteer
Posts: 1159
Joined: Sat Jul 02, 2011 9:47 am

Re: [Solved] Random error messages with 28000 line macro

Post by karolus »

John_Ha wrote: Wed Jul 27, 2022 10:34 pm 28000 lines of linear code is a disaster waiting to happen ... and it has happened.

Break it into manageable modules.
BASIC anyway is a disaster, the (quantity of disaster) can be approximatly calculated by

Code: Select all

QOD = lines_of_code^2
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
Post Reply