[Solved] How do I break a long macro code line so it wraps?

Keyboard macros or custom scripts

[Solved] How do I break a long macro code line so it wraps?

Postby alf50 » Sat Jan 09, 2021 3:35 am

How do I extend a long Macro Code Line so I do not have to scroll right to see it? I thought the method was to enter an underscore followed by a carriage return to do that, but it does not seem to work.

[Solved] OpenOffice and LibreOffice will both handle my long PDF configuration line when coding to run in the Mac OS X environment.
The problem was that where OpenOffice runs under Catalina(10.15), the Java Run Time environment supplied by Apple in their normal distribution, worked as released by Apple. In Apple's Big Sur(10.16) version needed not only a Mac Compatible, Java Run Time, but the latest Software Development Kit (SDK) to run with minor, fixable issues. Still have issues thought. Running External applications using OpenOffice Code is different than running external applications using LibreOffice Code. For Example, to run an Apple Script to Quit Open Office without I/O error (a problem many people have but few have provided simple solutions to fix in Mac OS environments over the last 10 years), I trigger a simple Apple Script in OpenOffice using the following code:
Code: Select all   Expand viewCollapse view
Sub SaveClose
   dim CpathNm as string, CpNQoo as string, sPath1 as string
rem ********************************************************************
rem First, get the path to the Document you are currently in.
rem ********************************************************************
   GlobalScope.BasicLibraries.loadLibrary("Tools")
   CpathNm=DirectoryNameoutofPath(ThisComponent.getURL(),"/")
   L = LEN(CpathNm)
  '   MsgBox "CpathNm/L= " & CpathNm & "/ " & L
rem ********************************************************************
rem Next, The path returned starts with "file:///Users/MyDir/... then on to
rem          whichever directories your application/Document to be saved is running in.
rem I keep the Qoo.app and QLo.app AppleScipts in an Application Folder,
rem but to launch them, I must know where the "/" is after "MyDir" to get the launch Path right.
rem The following code handles the variable length of "MyDir" associated with different computers.
rem ********************************************************************
   If L < 15 then goto SnC2:
   for N = 15 to L
    If MID(CpathNm,N,1) = "/" then
      M = N
      CpNQoo = LEFT(CpathNm,M) & "Applications/Qoo.app/Contents/MacOS/applet"
     'msgbox "CpNQoo = " & CpNQoo
      goto SnC1:
     Else
    End If
   next N
   msgbox "Something is wrong, CpNQoo = " & CpNQoo
   goto SnC2:
rem ----------------------------------------------------------------------
SnC1:
   sPath1= CpNQoo
   oSvc = createUnoService("com.sun.star.system.SystemShellExecute")
   oSvc.execute(sPath1, "" , 0)
rem ----------------------------------------------------------------------
rem In Libra Office The apple script QLo is triggered with
rem  the following code:(without the rem's)
rem ----------------------------------------------------------------------
rem   sPath1= CpNQoo
rem   shell(sPath1)
rem ----------------------------------------------------------------------
rem The AppleScript waits 3 seconds before quitting OpenOffice,
rem which gives enough time for your document to be
rem stored and disposed of.
rem  on run
rem    delay 3
rem     tell application "OpenOffice"
rem      quit
rem     end tell
rem  end run
rem ----------------------------------------------------------------------   
   dim oDoc as Object
   dim oDocCtrl as Object
   oDoc = ThisComponent
   oDocCtrl = oDoc.getCurrentController()
   oDoc.store()                    ' Save...
   DisposeDocument(oDoc)   ' ... and close
SnC2:
End Sub

This is the first time I have provide a complete working Save & Close Subroutine, but there has been so many unusable suggestions out there over the years, that I hope this will really help Mac Users to use OpenOffice and LIbreOffice with macros, more effectively.
Last edited by alf50 on Mon Jan 11, 2021 5:47 am, edited 3 times in total.
OpenOffice 4.1.8 on Mac Catalina(10.15.7) and MS Windows10
User avatar
alf50
 
Posts: 107
Joined: Sun Jun 13, 2010 2:55 pm

Re: How do I break a long macro code line so it wraps?

Postby FJCC » Sat Jan 09, 2021 5:43 am

The following works for me to add 5 to the value cell A1 on the first sheet. What is your code?
Code: Select all   Expand viewCollapse view
sub Main
oSheet = ThisComponent.getSheets().getByIndex(0)
oCelda = oSheet.getCellrangeByName("A1")
oCelda.Value = oCelda.Value + _
               5
End Sub
Windows 10 and Linux Mint, since 2017
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: 8114
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: How do I break a long macro code line so it wraps?

Postby Zizi64 » Sat Jan 09, 2021 9:18 am

I thought the method was to enter an underscore followed by a carriage return to do that, but it does not seem to work.

Yes it is, but never split a single command to two parts. (I just guessing, why this not worked for you...)


Please upload a sample file or the formatted code list here.

Use the CODE tags in the edit box of this forum:

Code: Select all   Expand viewCollapse view
Here is _
my code
Tibor Kovacs, Hungary; LO6.1.6, 6.4.7 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.1.1;AOO4.1.9
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 9840
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: How do I break a long macro code line so it wraps?

Postby JeJe » Sat Jan 09, 2021 12:12 pm

Code: Select all   Expand viewCollapse view
Sub Main

a = (2 * 6) + _
5
msgbox a

st = "fish " & _
"bats"
msgbox st
End Sub
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1533
Joined: Wed Mar 09, 2016 2:40 pm

Re: How do I break a long macro code line so it wraps?

Postby alf50 » Sat Jan 09, 2021 4:36 pm

I am using a Mac Running 10.15.7 (Catalina) and Openoffice 4.1.8. I tried going to the Latest Mac OS X 10.16.1 (Big Sur), but when I tried to run OpenOffice, It Crashed almost immediately after opening. zizi64 suggested trying LibraOffice instead, since it has been updated more frequently. I did that, but then my code would not work. Any Basic Macro code that was over 250 characters in length simply did not work.
One of my Macros was recorded in OpenOffice to automate the export of a single page, PDF file of a page of my Calc application. That single macro line of code is ~3800 characters long and Is included in the entry below: As you can see, this is a LONG com.sun.star... command with Arrays buried inside an Array. It was ONE LONG LINE OF CODE!! When I try to use a "_" & CarriageReturn (the enter key on a Mac), I simple get an error when I run the macro. Any Suggestions?
Code: Select all   Expand viewCollapse view
args1(2).Value = Array(Array("UseLosslessCompression",0,false,_
com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("Quality",0,90,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("ReduceImageResolution",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("MaxImageResolution",0,300,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("UseTaggedPDF",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("SelectPdfVersion",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("ExportNotes",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("ExportBookmarks",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("OpenBookmarkLevels",0,-1,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("UseTransitionEffects",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("IsSkipEmptyPages",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("IsAddStream",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("EmbedStandardFonts",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("FormsType",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("ExportFormFields",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("AllowDuplicateFieldNames",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("HideViewerToolbar",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("HideViewerMenubar",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("HideViewerWindowControls",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("ResizeWindowToInitialPage",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("CenterWindow",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("OpenInFullScreenMode",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("DisplayPDFDocumentTitle",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("InitialView",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("Magnification",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("Zoom",0,100,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("PageLayout",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("FirstPageOnLeft",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("InitialPage",0,1,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("Printing",0,2,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("Changes",0,4,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("EnableCopyingOfContent",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("EnableTextAccessForAccessibilityTools",0,true,_
com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("ExportLinksRelativeFsys",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("PDFViewSelection",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("ConvertOOoTargetToPDFTarget",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("ExportBookmarksToPDFDestination",0,false,_
com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("_OkButtonString",0,"",com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("EncryptFile",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("PreparedPasswords",0,,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("RestrictPermissions",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("PreparedPermissionPassword",0,Array(),com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("",0,,com.sun.star.beans.PropertyState.DIRECT_VALUE))
OpenOffice 4.1.8 on Mac Catalina(10.15.7) and MS Windows10
User avatar
alf50
 
Posts: 107
Joined: Sun Jun 13, 2010 2:55 pm

Re: How do I break a long macro code line so it wraps?

Postby Zizi64 » Sat Jan 09, 2021 5:49 pm

Please upload the whole code of the recorded Sub. We can not try it without the full code.
Tibor Kovacs, Hungary; LO6.1.6, 6.4.7 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.1.1;AOO4.1.9
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 9840
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: How do I break a long macro code line so it wraps?

Postby Villeroy » Sat Jan 09, 2021 5:50 pm

It has to be <space>_
I recommend Python as macro language instead of Basic.
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
User avatar
Villeroy
Volunteer
 
Posts: 29713
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How do I break a long macro code line so it wraps?

Postby alf50 » Sat Jan 09, 2021 6:03 pm

Placing a Space before the Underscore or both before and after the underscore does not work.
OpenOffice 4.1.8 on Mac Catalina(10.15.7) and MS Windows10
User avatar
alf50
 
Posts: 107
Joined: Sun Jun 13, 2010 2:55 pm

Re: How do I break a long macro code line so it wraps?

Postby JeJe » Sat Jan 09, 2021 6:47 pm

This works for me - no crash.

Code: Select all   Expand viewCollapse view

Sub Main
dim args1(2) as new com.sun.star.beans.PropertyValue

args1(2).Value = Array(Array("UseLosslessCompression",0,false, _
com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("Quality",0,90,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("ReduceImageResolution",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("MaxImageResolution",0,300,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("UseTaggedPDF",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("SelectPdfVersion",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("ExportNotes",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("ExportBookmarks",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("OpenBookmarkLevels",0,-1,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("UseTransitionEffects",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("IsSkipEmptyPages",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("IsAddStream",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("EmbedStandardFonts",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("FormsType",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("ExportFormFields",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("AllowDuplicateFieldNames",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("HideViewerToolbar",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("HideViewerMenubar",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("HideViewerWindowControls",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("ResizeWindowToInitialPage",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("CenterWindow",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("OpenInFullScreenMode",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("DisplayPDFDocumentTitle",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("InitialView",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("Magnification",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("Zoom",0,100,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("PageLayout",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("FirstPageOnLeft",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("InitialPage",0,1,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("Printing",0,2,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("Changes",0,4,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("EnableCopyingOfContent",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("EnableTextAccessForAccessibilityTools",0,true, _
com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("ExportLinksRelativeFsys",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("PDFViewSelection",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("ConvertOOoTargetToPDFTarget",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("ExportBookmarksToPDFDestination",0,false, _
com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("_OkButtonString",0,"",com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("EncryptFile",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("PreparedPasswords",0,,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("RestrictPermissions",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("PreparedPermissionPassword",0,Array(),com.sun.star.beans.PropertyState.DIRECT_VALUE), _
Array("",0,,com.sun.star.beans.PropertyState.DIRECT_VALUE))
End Sub


com.sun.star.beans.PropertyState.DIRECT_VALUE =0 so you can put a shorter

Code: Select all   Expand viewCollapse view
Array("Quality",0,90,0)


And then you could use variables for the arrays

Code: Select all   Expand viewCollapse view
a =  Array("Quality",0,90,0)
b =Array("ReduceImageResolution",0,false,0)

args1(2).Value = Array(a,b,c,d)

Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1533
Joined: Wed Mar 09, 2016 2:40 pm


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 1 guest