* sorting tables by v

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.
User avatar
tatewise
Megastar
Posts: 28342
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: sorting tables by v

Post by tatewise »

Use a separate sort(a,b) function, so you can debug it just like any other function.

Code: Select all

function sort(a,b)
  if a == nil then
    zz = 0   -- break here to detect local 'a' (a nil value)
  end
  local ans = a.KLIST .. ' ' .. dir .. ' ' .. b.KLIST
  return ans  -- break here to see what is returned
end

table.sort(USRIDX,sort)
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: sorting tables by v

Post by Ron Melby »

Thanks that solved it.

the error returned is wrong. running around chasing the wrong error.

the upshot is you may not glue up or make the
a < b statement a variable it doesn't do recursive gluing.

it has to be an 'object' statement

so, in my code it will have to be a series of elseifs
if dir = '<' then
table.sort(usridx,( function (a, b) return a < b end)
elseif dir = '>' then
table.sort(usridx,( function (a, b) return a > b end)

and so on ... or perhaps a function table? oh, that would be a new one for me.
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28342
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: sorting tables by v

Post by tatewise »

Yes, a function table will work.

Code: Select all

function SortLess()
	table.sort(usridx,function (a, b) return a < b end)
end

function SortMore()
	table.sort(usridx,function (a, b) return a > b end)
end

local tblFunc = { ["<"]=SortLess; [">"]=SortMore; }
dir = "<"
tblFunc[dir]() -- Invokes SortLess or SortMore depending on character in dir
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: sorting tables by v

Post by Ron Melby »

I am going to try it when I get home. looks like a simple enough deal
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: sorting tables by v

Post by Ron Melby »

Code: Select all

Name                            S      Dates       SVCDate  War                    ARM                 Rank              OTH                                                                
COVEY, James Jr. (IV)           M (1715 - 1782) 1756-1763   French and Indian Wars                                                                                                          
COVEY, Joseph Sr.               M (1754 - 1839) Sep 1775    Revolutionary War      Militia             PVT                                                                                  
COVEY, Kenneth William          M (1915 - 1988)             WWII                   US Army             TEC5                                                                                 
COVEY, Marvin Clifford          M (1894 - 1960)             WWI                                                                                                                             
COVEY, Roger L.                 M (1925 - 2004)             WWII                   US Army             TEC5                                                                                 
COVEY, William Luther           M (1825 - 1864) 22 Feb 1864 Civil War              US Army             PVT               Enlisted                                                           
                                                5 May 1864  Civil War              US Army             PVT               Killed in Action                                                   
                                                                                                                                                                                         
COVEY, William Sr.              M (1748 - 1838)             Revolutionary War                                                                                                               
CROSS, Cleo Clair               M (1921 - 1982)             WWII                   US Army             CPL                                                                                  

ok, that is looking pretty good, it is working as I had imagined. I have to work on my centering routine, and make a table lookahead field, so that where I have someone like William Luther Covey who has multiple entries, I will put a line before as well as a line after.
FH V.6.2.7 Win 10 64 bit
Post Reply