Page 1 of 1

Searching with Array

Posted: Tue May 04, 2021 8:00 am
by Silvio.Falconi
I have never liked arrays, in fact I hate them !!!

I have an array aSectors
Image

first column := sectors
Second column:= element code


then I have another array aPricesOld

Image

I wish check on aPricesOld each record if have the same sector and Element code of aSectors
if not is the same the procedure must save an X on field number 8 of aPricesOld array

I made

Code: Select all | Expand

cSector:=""
cElement:= ""

For n= 1 to Len( apricesOld )
         cSector:= apricesOld[n][3]
         cElement:= apricesOld[n][2]
            If AScan( aSectors, cSector ) != 0  .and.  AScan( asectors, cElement ) != 0
                  apricesOld[n][8]:= "X"
          Endif
       Next


why not run ok ?
sample see the second image the record number 1 and seven are not the same and must have the X

Re: Searching with Array

Posted: Tue May 04, 2021 8:17 am
by Silvio.Falconi
Now I made a Test and I found the opposite :) I told you that I hate arrays I don't get along with them


Image

Code: Select all | Expand


 For n= 1 to Len( aPricesOld )
         cSector:= aPricesOld[n][3]
         cElement:= aPricesOld[n][2]

         For k=1 to Len( aSectors)
            IF aSectors[k][1]= cSector  .and.;
               aSectors[k][2]= cElement
   
               aPricesOld[n][8]:= "X"
            Endif
             Next
       Next



so funny,but I wanted the opposite, look, it was not easy to find the opposite of what I had to find, I am a genius in this field !!!!

Re: Searching with Array

Posted: Tue May 04, 2021 8:33 am
by Silvio.Falconi

Code: Select all | Expand

For n= 1 to Len( aPricesOld )
         cSector:= aPricesOld[n][3]
         cElement:= aPricesOld[n][2]
                aPricesOld[n][8]:= "X"
         For k=1 to Len( aSectors)
            IF aSectors[k][1]= cSector  .and.;
               aSectors[k][2]= cElement
               aPricesOld[n][8]:= " "
            Endif
             Next
       Next


ok now run, Do you have another easier idea?

Re: Searching with Array

Posted: Tue May 04, 2021 7:54 pm
by nageswaragunupudi

Code: Select all | Expand

for n= 1 to Len( aPricesOld )
   cSector     := aPricesOld[ n ][ 3 ]
   cElement    := aPricesOld[ n ][ 2 ]

   if AScan( aSectors, { |a| a[ 1 ] = cSector .and. a[ 2 ] = cElement } ) == 0
      aPricesOld[ n, 8 ]   := "X"
   endif
next
 


or

Code: Select all | Expand

for n= 1 to Len( aPricesOld )
   cSeek       := aPricesOld[ n ][ 3 ] + aPricesOld[ n ][ 2 ]

   if AScan( aSectors, { |a| ( a[ 1 ] + a[ 2 ] ) == cSeek } ) == 0
      aPricesOld[ n, 8 ]   := "X"
   endif
next
 

Re: Searching with Array

Posted: Tue May 04, 2021 9:42 pm
by Silvio.Falconi
thanks rao
but not run with ypour tests

run only with

Code: Select all | Expand

For n= 1 to Len( aPricesOld )
         cSector:= aPricesOld[n][3]
         cElement:= aPricesOld[n][9]
                aPricesOld[n][8]:= "X"
         For k=1 to Len( aSectors)
            IF aSectors[k][1]= cSector  .and.;
               aSectors[k][2]= cElement
               aPricesOld[n][8]:= " "
            Endif
             Next
       Next