Ask Your Question

Password protected Macro lenght limited

asked 2015-06-09 09:36:43 +0100

Mr.Crocodile gravatar image

updated 2015-09-27 18:25:04 +0100

Alex Kemp gravatar image

Windows 7 64bit, LibreOffice I prepared a complex macro made of about 50 subs with about 5300 lines of code. I would like to password protect it but when I try to save the document (Calc) I receive an error indication related to the fact that the library seems to be too large to be stored in a binary format. So it is impossible to protect it without splitting it in smaller modules. This is a problem because the subs are linked by some global variables. I found this document BasicImageSizeIncreaseWarning.odt where it is explained that the problem is related to the old 16bit bound limit (65535 characters). My macro contains about 200000 characters. From that documet and also from here Increase code size that basic can handle I think to understand that this issue was solved years ago. But the problem is still present. What did I not understand?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2015-07-26 06:15:39 +0100

doug gravatar image

One of the comments in the linked bug report documents that the issue was not fixed for password protection, and the old format continues to apply in that situation.

Consider converting the globals into return values for functions, and call the functions from other modules using the getScriptProvider method (noted here). An example:

REM -- Module 1--

Sub Main
Dim a(0),b(0),c(0) As Variant
scpr = ThisComponent.getScriptProvider

scriptLoc = "Standard.Module2"
funcName = "DemoGlobalSim"
lang = "Basic"
locName = "document"

scmod = scpr.getScript("" & scriptLoc & "." & funcName & _
      "?language=" & lang & "&location=" &  locName)

globalVal = scmod.invoke(a,b,c)
MsgBox globalVal
end Sub

REM -- End Module 1 --

REM -- Module 2 --

Function DemoGlobalSim
    DemoGlobalSim = "Hello Global Value"
End Function

REM -- End Module 2 --

(if this answers your question, please accept the answer by clicking the check (image description) to the left)

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2015-06-09 09:36:43 +0100

Seen: 285 times

Last updated: Jul 26 '15