[Solved] Break long string constant across multiple lines

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
estatistics
Posts: 25
Joined: Tue Oct 13, 2015 8:13 pm
Location: worldwide

[Solved] Break long string constant across multiple lines

Post by estatistics »

 Edit: Split from [Solved] How do I break a long macro code line so it wraps? for new person with new question in solved topic. 
Hello,
I use Libre office 7.3.0 and the starbasic Macro command to break long code dont work

Code: Select all

Const SCells = "B17:C28,E17:G28,L17:O28,T17:V28,AA17:AE28,AN17:AR28, _
BB17:BD28,BO17:BS28,BY17:CB28,CG17:CI28,CS17:CW28,DB17:DF28,DL17:DN28, _
DU17:DX28,EF17:EK28,ET17:EV28,FA17:FD28,FJ17:FL28,FV17:FZ28,GD17:GF28,
GM17:GO28"
 splitCells = Split(SCells,",")

sub Cells_range

for i = 0 to 2 step 1

print splitCells(i)

next i 

end sub

Last edited by Hagar Delest on Wed Sep 01, 2021 10:51 am, edited 1 time in total.
Reason: tagged solved.
OpenOffice 4.2.8.2 on Lubuntu
User avatar
karolus
Volunteer
Posts: 1158
Joined: Sat Jul 02, 2011 9:47 am

Re: [Solved] How do I break a long macro code line so it wra

Post by karolus »

Hallo

Code: Select all

sub Cells_range

    SCells = "B17:C28,E17:G28,L17:O28,T17:V28,AA17:AE28,AN17:AR28,"+ _
             "BB17:BD28,BO17:BS28,BY17:CB28,CG17:CI28,CS17:CW28,"+ _
             "DB17:DF28,DL17:DN28,DU17:DX28,EF17:EK28,ET17:EV28,"+ _
             "FA17:FD28,FJ17:FL28,FV17:FZ28,GD17:GF28,GM17:GO28"

    splittedCells = Split(SCells,",")

    for each range In splittedCells
        print range
    next 

end sub
and just for Fun, the python-equivalent:

Code: Select all

def Cells_range():

    Cells = ("B17:C28,E17:G28,L17:O28,T17:V28,AA17:AE28,AN17:AR28,"
             "BB17:BD28,BO17:BS28,BY17:CB28,CG17:CI28,CS17:CW28,"
             "DB17:DF28,DL17:DN28,DU17:DX28,EF17:EK28,ET17:EV28,"
             "FA17:FD28,FJ17:FL28,FV17:FZ28,GD17:GF28,GM17:GO28")



    for range_name in Cells.split(","):
        print(range_name) 
Last edited by karolus on Sun Aug 29, 2021 8:53 pm, edited 1 time in total.
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)
User avatar
estatistics
Posts: 25
Joined: Tue Oct 13, 2015 8:13 pm
Location: worldwide

Re: [Solved] How do I break a long macro code line so it wra

Post by estatistics »

I found that in Strings in starbasic Macros in LibreCalc:

you must end the quotes then
break the line with the line-continuation starbasic / vba space-underscore character " _"
and then use "&" which join strings
all broken strings must be in quotes in their beginning and in their ends.
e.g.

Code: Select all

Const SCells = "B17:C28,E17:G28,L17:O28," _
         & "BB17:BD28,BO17:BS28," _
         & "BY17:CB28,CG17:CI28,CS17:CW28"

      print SCells
or

Code: Select all

Const SCells = "B17:C28,E17:G28,L17:O28,T17:V28,AA17:AE28,AN17:AR28," & _
    "BB17:BD28,BO17:BS28,BY17:CB28,CG17:CI28,CS17:CW28,DB17:DF28,DL17:DN28," & _
    "DU17:DX28,EF17:EK28,ET17:EV28,FA17:FD28,FJ17:FL28,FV17:FZ28,GD17:GF28," & _
    "GM17:GO28"
ps. https://stackoverflow.com/questions/689 ... 2#68975902
OpenOffice 4.2.8.2 on Lubuntu
Post Reply