FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Searching with Array
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Searching with Array
Posted: Tue May 04, 2021 08:00 AM
I have never liked arrays, in fact I hate them !!!

I have an array aSectors


first column := sectors
Second column:= element code


then I have another array aPricesOld



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 (fw): Select all Collapse
 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
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 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
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Searching with Array
Posted: Tue May 04, 2021 08: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




Code (fw): Select all Collapse
 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 March-April 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
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Searching with Array
Posted: Tue May 04, 2021 08:33 AM
Code (fw): Select all Collapse
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 March-April 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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Searching with Array
Posted: Tue May 04, 2021 07:54 PM
Code (fw): Select all Collapse
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 (fw): Select all Collapse
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
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Searching with Array
Posted: Tue May 04, 2021 09:42 PM
thanks rao
but not run with ypour tests

run only with

Code (fw): Select all Collapse
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 March-April 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

Continue the discussion