* Coding query

Homeless Posts from the old forum system
Locked
avatar
MartinA
Gold
Posts: 22
Joined: 17 Aug 2012 09:00
Family Historian: None

Coding query

Post by MartinA »

strName = fhGetItemText(pi,'INDI.CENS[year=1911].SOUR[1]>OBJE[1]>TITL')

works fine.

So does

strCens='INDI.CENS[year=1911].SOUR[1]>OBJE[1]>TITL'
strName = fhGetItemText(pi,strCens)

But

strCens=''INDI.CENS[year=1911].SOUR[1]>OBJE[1]>TITL''
strName = fhGetItemText(pi,strCens)

does not.

Hence nor does

strCens=''INDI.CENS[year='..strDate..'].SOUR[1]>OBJE[1]>TITL''.
strName = fhGetItemText(pi,strCens)

where strDate is a user input.

Is there a way of doing this, i.e. having a user input date in the fhGetItemText function?

Martin

ID:6444
User avatar
tatewise
Megastar
Posts: 28335
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Coding query

Post by tatewise »

In the How to Write Plugins help, see the Introduction to Lua > Lua Quick Guide sub-section on STRINGS.

Also see Lua 5.1 Reference Manual very near the beginning under 2.1 - Lexical Conventions it defines Literal strings.

'INDI.CENS[year=1911].SOUR[1]>OBJE[1]>TITL' is a text string using single quote delimiters.
'INDI.CENS[year=1911].SOUR[1]>OBJE[1]>TITL' is an identical text string using double quotes.
INDI.CENS[year=1911].SOUR[1]>OBJE[1]>TITL is the actual text string in both cases.

''INDI.CENS[year=1911].SOUR[1]>OBJE[1]>TITL'' defines a different text string:-
'INDI.CENS[year=1911].SOUR[1]>OBJE[1]>TITL' as it has a single quote character at front and back.
(This is a technique for including single quote chars in a text string).
c.f.
''INDI.CENS[year=1911].SOUR[1]>OBJE[1]>TITL'' defines
'INDI.CENS[year=1911].SOUR[1]>OBJE[1]>TITL'
(This is a technique for including double quote chars in a text string).

The following will all work OK providing that strYear is a four digit string:-
Use single quotes
strName = fhGetItemText(pi,'INDI.CENS[year='..strYear..'].SOUR[1]>OBJE[1]>TITL')
or use double quotes
strName = fhGetItemText(pi,'INDI.CENS[year='..strYear..'].SOUR[1]>OBJE[1]>TITL')
or even single quotes and double quotes
strName = fhGetItemText(pi,'INDI.CENS[year='..strYear..'].SOUR[1]>OBJE[1]>TITL')
or single quotes in a variable
strCens='INDI.CENS[year='..strYear..'].SOUR[1]>OBJE[1]>TITL'
strName = fhGetItemText(pi,strCens)

or double quotes in a variable
strCens='INDI.CENS[year='..strYear..'].SOUR[1]>OBJE[1]>TITL'
strName = fhGetItemText(pi,strCens)


(Any number of digits in strYear would also be syntactically OK, but there are no Census years before 1790).
avatar
MartinA
Gold
Posts: 22
Joined: 17 Aug 2012 09:00
Family Historian: None

Coding query

Post by MartinA »

Right, thanks Mike.

I understand that now. I'll give them a try although I thought I'd already tried at least one of those.

Thanks again.

Martin
User avatar
Jane
Site Admin
Posts: 8507
Joined: 01 Nov 2002 15:00
Family Historian: V7
Location: Somerset, England
Contact:

Coding query

Post by Jane »

Don't forget you can use the debug to check the value of your data reference string, if you build it as a variable before use.
avatar
MartinA
Gold
Posts: 22
Joined: 17 Aug 2012 09:00
Family Historian: None

Coding query

Post by MartinA »

Yes, thanks Jane. I'm getting there, but it's a fairly steep learning curve from when I played around with VB years ago. The main problem was with strings that had accidental spaces at the beginning. I only found them by checking string length against the output where it wasn't obvious.

I finally have a working version that reads all the files (census images) that I have stored in a given census date folder. It then reads all the multimedia that FH holds for the same year and picks out the names that have a file not linked in.

It also showed up some anomalies in my file naming system which helped rationalise things.

As I said previously, I don't think this is worth uploading, because any other user would have to edit it to match their filepaths.

Thanks for the help,

Martin
Locked