* how to get #entries.

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
Post Reply
User avatar
Ron Melby
Megastar
Posts: 917
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

how to get #entries.

Post by Ron Melby »

so, I am trying to determine, (since it should be non-nil if it exists)
how do I get the NAME[ ], SPOU[], MARR[] and so on, number of entries?

nent = #NAME
sent = #SPOU
ment = #MARR

That isnt going to work, I know that before I even test it.
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28333
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: how to get #entries.

Post by tatewise »

You are correct the # length operator only applies to Lua data items and not GEDCOM structures.
Unfortunately, you have to count them using a while loop.
e.g.

Code: Select all

local ptrIndi = fhNewItemPtr()
ptrIndi:MoveToFirstRecord("INDI")
while ptrIndi:IsNotNull() do
	local intName = 0
	local ptrName = fhNewItemPtr()
	ptrName:MoveTo(ptrIndi,"~.NAME")
	while ptrName:IsNotNull() do
		intName = intName + 1
		ptrName:MoveNext("SAME_TAG")
	end
	print(intName)
	ptrIndi:MoveNext()
end
You could make the counting loop a function with parameter (ptrItem) and return the count.
e.g.

Code: Select all

local function intInstances(ptrItem)	-- Count number of instances of Item
	local intItem = 0
	while ptrItem:IsNotNull() do
		intItem = intItem + 1
		ptrItem:MoveNext("SAME_TAG")
	end
	return intItem
end -- local function intInstances

local ptrIndi = fhNewItemPtr()
ptrIndi:MoveToFirstRecord("INDI")
while ptrIndi:IsNotNull() do
	local intName = intInstances( fhGetItemPtr(ptrIndi,"~.NAME") )
	print(intName)	-- Diagnostic printout of instances
	ptrIndi:MoveNext()
end
Then you can use function intInstances to count any data item instances.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Ron Melby
Megastar
Posts: 917
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: how to get #entries.

Post by Ron Melby »

thats sort of what my code looks like

I thought first #NAME, realized while it looks ok, its just a text string, and wont work
then I thought about pairs, but if there is a table behind it I cant get at it.

strDataOffset = "~.NAME[" .. ln .. "]:SURNAME_FIRST"
is what I ended up with

where ln is the last name in the structure
and it works fairly well for what I want, but doesnt account for non-marraiges, husbands I dont know, and children out of wedlock..but I can work with it.
FH V.6.2.7 Win 10 64 bit
User avatar
Ron Melby
Megastar
Posts: 917
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: how to get #entries.

Post by Ron Melby »

sideways a little from the subject, but still this plugin, so if it needs moving...

reading what I can find of the spec: require can be anywhere in the file, is that correct?

also, I have been trying to come to grips with coroutines and fhUpdateDisplay() trying to find a way to update the output tables when I make a change from the screen, and do not think it is possible, or am I missing something?
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28333
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: how to get #entries.

Post by tatewise »

I think require needs to executed before the components of the module are called.
Usually the require is invoked at the very start of the Plugin. Why put it anywhere else?

coroutines are quite tricky, especially since you still seem to be struggling to grasp more basic concepts.
How were you hoping to use coroutines?

fhUpdateDisplay() only applies to windows that were on display in FH before the Plugin was run.
It cannot possibly apply to the Result Set output because that does not exist until after the Plugin has completed.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Ron Melby
Megastar
Posts: 917
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: how to get #entries.

Post by Ron Melby »

then what I want doesnt appear to be doable.
FH V.6.2.7 Win 10 64 bit
Post Reply