I’m having an issue processing array elements within a global variable. The following code processes a carriage return array of names, created with arraybuild( , by comparing the names in one file to another. If the names in the array are in the second database, they will be selected. After a lot of investigation, I am finding that every 33rd record is not being compared. I added messages displaying the count and the name being processed by the array. The count skips 33, 66, 99… It happens constantly over different sets of names and several databases. I even duplicated a database, removed some records and loaded gNames with an arrayselectedbuild( of the database, then compared it with the original and it skipped every 33rd record. Is there a ghost in the machine?
Global gNames, gTotal
gNames=arraybuild(¶,“”,{Name})
gTotal=arraysize(gNames,¶)
Open the second database
Local lcount
lcount = 1
Select «Name» = array(gNames,lcount,¶)
Loop
lcount = lcount+1
SelectAdditional «Name» = array(gNames,lcount,¶)
Until lcount = gTotal
I would strongly recommend looparray for this type of application, primarily because your code will be so much simpler.
let gnames = arraybuild(cr(),"",{Name}}
open the second database
looparray gnames,cr(),gname,lcount
if lcount = 1
select Name = gname
else
selectadditional Name = gname
endif
endloop
But actually, I think there is a much simpler technique.
let gnames = arraybuild(cr(),"",{Name}}
open the second database
select arraycontains(gnames,Name,cr())
Notice that in both cases, only local variables are needed. You don’t need global variables unless you are planning on using these values later in some other procedure.
I hate to break it to you, but this technique would have worked the same in Panorama 6. I’m not sure when arraycontains( was added, but it was no later than 5.5. The arraysearch( function could also have been used similarly, and that goes back to Panorama 4 or maybe even Panorama 3.