FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour ASCAN question
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
ASCAN question
Posted: Wed Apr 26, 2017 11:09 PM

I have an array (aWork ) , and each element is an array with 4 elements:
The data arrays are:
[1] is a character field of 5 digits
[2] is a counter
[3] is an accumulator ( totals )
[4] is a description

I want to use aScan on aWork on the first element, and when I find the matching array, I will increment [2] and [3].

I can I use ASCAN( ) to search an element in an array of arrays ?

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 729
Joined: Tue Oct 18, 2005 06:49 PM
Re: ASCAN question
Posted: Thu Apr 27, 2017 12:59 AM
Tim,
From xharbour Language Reference Guide:
The array function AScan() traverses the array <aArray> for the value specified with <xbSearch>. If <xbSearch> is not a code block, AScan() compares the values of each array element for being equal with the searched value. If this comparison yields .T. (true), the function stops searching and returns the numeric position of the array element containing the searched value.
If a code block is passed for <xbSearch>, it is evaluated and receives as parameter the value of the current array element. The code block must contain a comparison rule that yields a logical value. AScan() considers the value as being found when the codeblock returns .T. (true). Otherwise the function proceeds with the next array element.
Code (fw): Select all Collapse
The example demonstrates simple and complex searching in arrays.
   PROCEDURE Main()
      LOCAL aArray := { "A", 1, Date(), NIL, .F. }

      // one dimensional array
      ? AScan( aArray, 1 )             // result: 2
      ? AScan( aArray, .F. )           // result: 5

      ? AScan( aArray, {|x| Valtype(x)=="D" } )
                                       // result: 3

      // two dimensional array
      aArray := Directory( "*.prg" )

      ? AScan( aArray, {|a| Upper(a[1]) == "TEST.PRG" } )
                                       // result: 28
   RETURN

Maybe by using the codeblock you can find a solution.
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: ASCAN question
Posted: Thu Apr 27, 2017 03:11 AM
Code (fw): Select all Collapse
if ( nAt := AScan( aWork, { |a| a[ 1 ] == cSeek } ) ) > 0
   aWork[ nAt, 2 ] += 1
   aWork[ nAt, 3 ] += nAmount
endif
Regards



G. N. Rao.

Hyderabad, India

Continue the discussion