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.
* how to get #entries.
how to get #entries.
FH V.6.2.7 Win 10 64 bit
- tatewise
- Megastar
- Posts: 28341
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: how to get #entries.
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.
You could make the counting loop a function with parameter (ptrItem) and return the count.
e.g.
Then you can use function intInstances to count any data item instances.
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
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
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
Re: how to get #entries.
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.
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
Re: how to get #entries.
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?
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
- tatewise
- Megastar
- Posts: 28341
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: how to get #entries.
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.
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