FindArrayCell
StepsTaken = FindArrayCell(SearchArray(), StartElement, ElementDelta, Number, SearchValueOrString)
 
Parameters:

    SearchArray() = The Array you wish to search
    StartElement = The address of starting element
    ElementDelta = The difference between elements
    Number = The number of elements you wish to search for
    SearchValueOrString = The Value or String you wish to search for
Returns:

    StepsTaken = The number sof steps taken from the starting position
 

      The FindArrayCell function can search either an entire array or a section, for either a value or a string. So FindArrayCell can be used on Integer, floating point arrays, and String arrays also. However the data type of SearchValueOrString (Integer/float/string) must match the type of array your searching. So you can only search for an integer values with within integer arrays.

      When FindArrayCell locates a matching element, it will return the number of steps it took to find this element from the starting location.

      One the most powerful features of PlayBASICs array commands is the ability to manipulate the data within any type of array, of any dimension. So these commands will work upon 1D arrays, 2D, 3D etc etc.



FACTS:


      * FindArrayCell returns a -1 if no matches were found.

      * When FindArrayCell find a matching element it returns the number searches that were required from the starting point.

      * FindArrayCell can be used upon Integer,Floating Point an String arrays.

      * FindArrayCell is much faster than manually clearing array elements yourself.




Mini Tutorial:


      This example creates an array called Table() and fill it with 10 values, ranging from 0 to 500. Then using [command name;] it locates

  
; Create a 1D Array called Table...
  Dim Table(10)
  
; Fill and Display the contents of table() array
  For lp =0 To 10
     table(lp)=lp*100
     Print Table(lp)
  Next
  
; Init the value to Search for in the table() array
  SearchVal=500
  
  FoundOffset= FindArrayCell(Table(),0,1,10,SearchVal)
  Print Str$(Searchval)+" Found at position:"+Str$(FoundOffset)
  
; Show the Display and wait for a key press
  Sync
  WaitKey
  


This Example would output

  
  0
  100
  200
  300
  400
  500
  600
  700
  800
  900
  1000
  500 Found at position:5
  




Filling a STRING Array with the string "Hello World"

  
; Create a 1D String Array...
  Dim Table$(10)
  
; Fill & Display the table() array
  For lp =0 To 10
     table$(lp)=ReadData$()
     Print Table$(lp)
  Next
  Print ""
  
; User Find to Search for a value in the table() array
  SearchString$="Allan"
  
  FoundOffset= FindArrayCell(Table$(),0,1,10,SearchString$)
  Print SearchString$+" Found at position:"+Str$(FoundOffset)
  
; Show the Display and wait for a key press
  Sync
  WaitKey
  
  Data "Kev","Bill","John","Peter","Allan"
  Data "Josh","Danny","Jenny","Amy","Andrew","Billy"
  


This example would output.

  
  Kev
  Bill
  John
  Peter
  Allan
  Josh
  Danny
  Jenny
  Amy
  Andrew
  Billy
  
  Allan Found at position:4
  


 
Related Info: SearchHighestArrayCell | SearchLowestArrayCell :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com