ASCAN question

ASCAN question

Postby TimStone » 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
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: ASCAN question

Postby George » 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: Select all  Expand view
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.
George
 
Posts: 725
Joined: Tue Oct 18, 2005 6:49 pm

Re: ASCAN question

Postby nageswaragunupudi » Thu Apr 27, 2017 3:11 am

Code: Select all  Expand view
if ( nAt := AScan( aWork, { |a| a[ 1 ] == cSeek } ) ) > 0
   aWork[ nAt, 2 ] += 1
   aWork[ nAt, 3 ] += nAmount
endif
 
Regards

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


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 106 guests