Looparray question/confusion


I am having trouble with a procedure using loop array. I am trying to select matching calf-cow pairs.

This is the code that isn’t working:
local dams,n,m,p
arraybuild dams,"/","",Unique,Select contains “Y"
if arraynumerictotal(dams,”/")=0
alertsheet “No records selected"
Select Select contains “Y"
looparray dams,”/”,m
p = lookup(“Cattle Database-Pedigree 3”,Unique,m,UniquePed)
selectadditional DamID = p and Fate contains "AtFoot"

It says the lookup( function fails to match.

However, the same lookup code, copied, with the m variable manually changed as follows, works perfectly.

p = lookup(“Cattle Database-Pedigree 3”,Unique,m,UniquePed)
selectadditional DamID = p and Fate contains “AtFoot”

I have checked the array is formatting correctly, by using the loop array with a message as follows:

arraybuild dams,"/","",Unique,Select contains “Y"
looparray dams,”/",m
message m

What am I doing incorrectly? and can I fix it?


It’s hard to tell exactly without seeing your data but I can make a couple of observations:

Are you looking up the “Cattle Database-Pedigree 3” database from another database? Which one contains the field, “Unique”?

Your lookup( function has no default parameter so you will get an error message if the search fails (see the help wizard).

I suggest that you avoid have field or variable names which are the same as Panorama X statements or functions (like “Select”).


Your code


is assigning a numeric value to m, but the looparray is assigning a text value to m. So better test code would be


Try that, and see if that makes any difference. If so, you could use a val( function to make sure a number is passed to the lookup, like this:

p - lookup("yada",Unique,val(m),UniquePed)

+100 on this suggestion. It can work, but so easy to make a confusing mistake with names like this. I don’t think you made a mistake with that in this example, but much clearer to avoid this.

Also, notice that on this forum you can make your code much easier to read by indenting it by four spaces, then the forum software formats it as code distinct from regular text.


Thankyou. The val(m) was the problem! Working well now.

Comment about field name noted. I only noticed the conflict when I went to write this programme, and thought there would be quite a few changes to make if I altered the field name. Will have another look though as you both think it may cause trouble.

Thanks for this - I tried to tab, or to make text italic, without success. I’ll certainly note this hint for future messages.

Thanks again.