Array selection is skipping records

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
Open the second database
Local lcount
lcount = 1
Select «Name» = array(gNames,lcount,¶)
lcount = lcount+1
SelectAdditional «Name» = array(gNames,lcount,¶)
Until lcount = gTotal

See this recent thread about loops skipping every 32nd iteration:

and specifically this:

— which yours does.

The quick and dirty workaround is to put a NOP statement after the Loop statement.

lcount = lcount+1
SelectAdditional «Name» = array(gNames,lcount,¶)
Until lcount = gTotal

Other solutions would be to rewrite the loop using a For or LoopArray statement. LoopArray would probably give you the best performance.

Thank you pcnewble and Dave Thompson. I need to improve my Forum search skills!

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
        selectadditional Name = gname

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.

Thanks Jim. The last method delivers instantaneous results.

I knew about select arraycontains( but I was converting an old Pan 6 procedure and I sometimes forget that, 10 years later, there’s a better way.

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.