Searching with Array

Searching with Array

Postby Silvio.Falconi » Tue May 04, 2021 8:00 am

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 view  RUN
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
Last edited by Silvio.Falconi on Tue May 04, 2021 8:31 am, edited 1 time in total.
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7072
Joined: Thu Oct 18, 2012 7:17 pm

Re: Searching with Array

Postby Silvio.Falconi » Tue May 04, 2021 8:17 am

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 view  RUN

 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 !!!!
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7072
Joined: Thu Oct 18, 2012 7:17 pm

Re: Searching with Array

Postby Silvio.Falconi » Tue May 04, 2021 8:33 am

Code: Select all  Expand view  RUN
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?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7072
Joined: Thu Oct 18, 2012 7:17 pm

Re: Searching with Array

Postby nageswaragunupudi » Tue May 04, 2021 7:54 pm

Code: Select all  Expand view  RUN
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 view  RUN
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
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Searching with Array

Postby Silvio.Falconi » Tue May 04, 2021 9:42 pm

thanks rao
but not run with ypour tests

run only with

Code: Select all  Expand view  RUN
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
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7072
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 72 guests