[Solved] AOO Basic string with embedded quotes

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
edhannahs
Posts: 9
Joined: Mon Aug 22, 2016 1:57 am

[Solved] AOO Basic string with embedded quotes

Post by edhannahs »

Was writing a simple macro to set formulae in cells as hyperlink function but stumbled across a problem with quotes as part of string. With trial and error I found something that works but don't understand the reasoning.

Code: Select all

qt               = """"
hyper            = "=HYPERLINK(" & qt & "#"
Sht2Name         = "Sheet2"
lnk              = hyper & Sht2Name & gt & qt & "; " & qt & Sht2Name & qt & ")"
lnk2             = hyper & Sht2Name & gt      & "; " & qt & Sht2Name & qt & ")"
lnk3             = hyper & "Sheet2" & qt      & "; " & qt & "Sheet2" & qt & ")"
shortlnk         = hyper & Sht2Name                                  & qt & ")"

This produces the following strings:
lnk =HYPERLINK("#Sheet2"; "Sheet2")
lnk2 =HYPERLINK("#Sheet2; "Sheet2")
lnk3 =HYPERLINK("#Sheet2"; "Sheet2")
shortlnk =HYPERLINK("#Sheet2")

lnk2 is not quoted properly (missing " after the first Sheet2) but the others are. I expected lnk2 to be correct but not lnk. I thought lnk2 was equivalent to lnk3. Why does it need the extra qt? shortlnk does not seem to need the extra qt. Just want to understand so I don't stumble around so much next time.

Windows 10
Last edited by edhannahs on Sun Nov 19, 2017 7:07 am, edited 1 time in total.
openoffice 4.1.2 on windows 10
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: OO Basic string with embedded quotes

Post by Zizi64 »

Try to use the code of the qoutes:

Code: Select all

qt = Chr(34)
Last edited by Zizi64 on Sat Nov 18, 2017 10:19 pm, edited 1 time in total.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
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: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: OO Basic string with embedded quotes

Post by Zizi64 »

Code: Select all

hyper & Sht2Name & gt & qt & "; " & qt & Sht2Name & qt & ")"
You have typed

Code: Select all

gt (GT)
instead of

Code: Select all

qt (QT)
in your sample.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
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.
edhannahs
Posts: 9
Joined: Mon Aug 22, 2016 1:57 am

Re: OO Basic string with embedded quotes [Solved]

Post by edhannahs »

Yes! Argh! Thank you! Stupid typos.
openoffice 4.1.2 on windows 10
Post Reply