I have been having a little play with adding some icons to my diagrams and decided I wanted to get a summary of what countries my ancestors were born and died in. After coming a little short in queries, I decided to finally jump into writing a plugin. I used to make MS Access programs in another life with VBA, so have some basic programming skills (I know my IT colleagues scoffed at VBA ) anyway, I am a little rusty.
I managed to write a little plugin which told me how many were born in each country. I used the sample database which was a little annoying as the places aren't consistent. All my places in my main database have 4 parts, but I should easily be able to tweak before I use it on my main file. I can also change it to do the same for death countries, however, my problem is having a table/grid combining the two, eg:
Code: Select all
Country No of Births No of Deaths
Australia 1 0
England 50 45
I tried to tweak what I did, but that didn't quite work. I have also had a look at the Jane's code for the Surname Summary Report, but I can't get that to work either. I think the way I would have approached it with Access/VBA is slightly different.
This is the code I wrote based on one of the examples which just deals with one type:
Code: Select all
tblCountryOfBirths = {} -- Define array for Countries of Birth
pi = fhNewItemPtr() -- declare pointer
pi:MoveToFirstRecord("INDI") -- point to the first individual record
while not pi:IsNull() do
-- For each Person Add the Country of Birth to the list
strPlace = fhGetItemText(pi,'%INDI.BIRT[1].PLAC>%')
strCountry = fhCallBuiltInFunction("TextPart",strPlace,3,0,"STD")
if (tblCountryOfBirths[strCountry] == nil) then
tblCountryOfBirths[strCountry] = 1
else
tblCountryOfBirths[strCountry] = tblCountryOfBirths[strCountry] + 1
end
pi:MoveNext()
end
-- Build Tables for the result set columns for Country and Qty
tblCountryOfBirth = {}
tblcount={}
ii = 0 -- line counter for result tables
for strCountry, iQty in pairs(tblCountryOfBirths) do
ii = ii + 1
tblCountryOfBirth[ii] = strCountry
tblcount[ii] = iQty
end
fhOutputResultSetColumn('Country of Birth', 'text',tblCountryOfBirth,ii,80,'align_left',2,true)
fhOutputResultSetColumn('Count', 'integer', tblcount,ii,40,'align_right',1,false)
1. When creating a table to store the information, do I need to do one for each column i.e. one for storing the number of births by country and a second one for storing the number of deaths? I thought that they would act like an array, but getting myself very confused.
2. In my head I thought I would have three columns and depending on what I was counting it would just update the relevant column, so find the country and +1 to the column.
Any pointers would be greatly appreciated it. I reckon if I can solve this problem, I might be able to do all sorts of things.
Thanks in advance!