[Solved] AOO Basic string with embedded quotes

Keyboard macros or custom scripts

[Solved] AOO Basic string with embedded quotes

Postby edhannahs » Sat Nov 18, 2017 7:59 pm

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   Expand viewCollapse view
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
edhannahs
 
Posts: 9
Joined: Mon Aug 22, 2016 1:57 am

Re: OO Basic string with embedded quotes

Postby Zizi64 » Sat Nov 18, 2017 9:35 pm

Try to use the code of the qoutes:
Code: Select all   Expand viewCollapse view
qt = Chr(34)
Last edited by Zizi64 on Sat Nov 18, 2017 10:19 pm, edited 1 time in total.
Tibor Kovacs, Hungary; LO4.4.7, LO5.3.7 on Win7x64Prof.
PortableApps, WinPenPack: LO3.3.0-LO5.4.2 and AOO4.1.3
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 6067
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: OO Basic string with embedded quotes

Postby Zizi64 » Sat Nov 18, 2017 9:38 pm

Code: Select all   Expand viewCollapse view
hyper & Sht2Name & gt & qt & "; " & qt & Sht2Name & qt & ")"


You have typed
Code: Select all   Expand viewCollapse view
gt (GT)
instead of
Code: Select all   Expand viewCollapse view
qt (QT)
in your sample.
Tibor Kovacs, Hungary; LO4.4.7, LO5.3.7 on Win7x64Prof.
PortableApps, WinPenPack: LO3.3.0-LO5.4.2 and AOO4.1.3
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 6067
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: OO Basic string with embedded quotes [Solved]

Postby edhannahs » Sun Nov 19, 2017 7:09 am

Yes! Argh! Thank you! Stupid typos.
openoffice 4.1.2 on windows 10
edhannahs
 
Posts: 9
Joined: Mon Aug 22, 2016 1:57 am


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: Exabot [Bot] and 4 guests