Page 1 of 1

'Text from Source' in a Source entry for an event

Posted: 17 Jan 2017 15:34
by quarlton
Hi

Can anyone point me in the right direction with picking up 'Text From Source' from a Source entry on an event.

The following works, but I can't find 'Text from Source' anywhere.
Caveat: The following assumes that all the entries are populated. It fails if not fully populated, but that is a different issue :?

pi4 is pointing to a Source entry on an Individual's Birth event

Code: Select all

pi5:MoveToFirstChildItem(pi4)		            --pi5 Now points to 'Where Within Source'
strWherewithinsource = fhGetValueAsText(pi5)   --Pick up 'Where within Source' value

pi5:MoveNext()					--pi5 now points to 'Data Recorded' aka "Entry Date"

pi5:MoveNext()					--pi5 now points to 'Certainty Assessment' aka "Asessment"

pi5:MoveNext()					--pi5 now points to 'Note'

Many thanks

Dave

Re: 'Text from Source' in a Source entry for an event

Posted: 17 Jan 2017 15:56
by Jane
The clue as always is the Data Reference eg

Code: Select all

%FACT.SOUR[1].DATA.TEXT[1]%
So you need the second child of pi5 (it's one of the "odd things" in the gedcom standard, or just use

Code: Select all

ptr:MoveTo(pi4,'~.DATA.TEXT')
Personally I prefer to use that method as you can be sure exactly what item you are getting, imported gedcoms may not be in the same order or contain the same fields. I also makes the code much easier to work out.

Re: 'Text from Source' in a Source entry for an event

Posted: 17 Jan 2017 16:25
by quarlton
Many thanks for that Jane, it solves the problem.

However, how do we determine the correct data references?

Code: Select all

ptr:MoveTo(pi4,'~.DATA.TEXT')
To use that method I need to discover the references for the other items.
I looked in the various Help files but didn't see (or I didn't recognise) anything that would point me to picking that reference.

Obviously I'm missing something quite basic :?

Re: 'Text from Source' in a Source entry for an event

Posted: 17 Jan 2017 17:06
by quarlton
I've just some testing and keep failing :cry:

The full code for testing is as follows
See last 6 lines of comments to see what each ptr is returning

Code: Select all

pi  = fhNewItemPtr()	     --Points to INDI record
pi2 = fhNewItemPtr()	     --Points to BIRT entry
pi3 = fhNewItemPtr()	     --Points to Children of BIRT entry
ptr = fhNewItemPtr()		  --Points to 'Where within source'


--Move to the first individual's record
pi:MoveToFirstRecord('INDI')    		--Points to first INDI record

--Move to their BIRT entry
pi2:MoveTo(pi,"~.BIRT")               --pi2 Points to BIRT

--Step through the children until find a SOUR record
pi3:MoveToFirstChildItem(pi2)			--This will be DATE then PLACE then ADDRESS followed by 
                                      --any SOURces then NOTE

while not pi3:IsNull() do	
		strTagType=fhGetTag(pi3)  	  	--Pick up the tag type
		if strTagType == 'SOUR' then	   --Check the TagType to see if it's SOUR. 
											       --If reach here then p3 should be pointing at the 
											       --Source for birth entry
			ptr:MoveTo(pi3,'~DATA.TEXT') --Now we want to pick up the value of 'Text from source'
												  --However, I find that at this point we have:
												  --pi points to the Individual
												  --pi2 points to the Birth entry for the Individual
												  --pi3 points to the Source entry for the Birth entry
												  --ptr returns (null)
		end
pi3:MoveNext()

end

Re: 'Text from Source' in a Source entry for an event

Posted: 17 Jan 2017 18:47
by DavidNewton
quarlton wrote:...
To use that method I need to discover the references for the other items.
I looked in the various Help files but didn't see (or I didn't recognise) anything that would point me to picking that reference.

Obviously I'm missing something quite basic :?
When editing a script the menu item Edit>Insert Data Reference will give you access to all.

David

Re: 'Text from Source' in a Source entry for an event

Posted: 17 Jan 2017 19:21
by tatewise
David is correct, that gives the same Data Reference Assistant as everywhere else in FH.
You use the popular names to find the data item and the Gedcom tags appear at the top.

As Jane has advised, you need to get out of the habit of using MoveToFirstChildItem() and MoveNext() where inappropriate, as tags are not necessarily ordered the way you might think.

Use pi3:MoveTo(pi,'~.BIRT.SOUR') to select 1st Source Citation.
Then use pi3:MoveNext('SAME_TAG') to loop through Source Citations while pi3:IsNotNull() do.

You are also overlooking the dot between tilde and tag, c.f. ~.DATA

Re: 'Text from Source' in a Source entry for an event

Posted: 17 Jan 2017 22:37
by quarlton
Many thanks to Jane, David and Mike

Between the three of you things have become much clearer.

Dave