scripting@wanadoo.nl




AScan()

http://www.scriptlogic.com/kixtart/FunctionLibrary_FunctionList.aspx


actual FunctionLibrary list on 'Scriptlogic' site printer-friendly mirror of UDF topic on 'scripting@wanadoo.nl' site     internal function since 4.20 close
26 March 2002 AScan()
AuthorScriptLogic Corporation
Action Searches all elements of an array for a matching expression.
SyntaxAScan (array, "string", start, end) 
Parameters
  • array (Required / Array) The array to search in.
  • string (Required / String) The string to search for.
  • start (Optional / Numeric) Lower array element to begin search on. If not specified, search begins at the first element [0].
  • end (Optional / Numeric) Upper array element to stop search on. If not specified, search ends at the last element. 
  • RemarksGood example of how to use the new FOR EACH command plus UBOUND() and VARTYPE() functions. 
    ReturnsReturns the element number of the array that matches the search String or -1 if no match found. 
    DependenciesNone. 
    Examples
    $months='January','February','March','April','May','June'
    $numelements=Ubound($months)
    $result=AScan($months,'May')
    IF ($result < 0) ; have to check for -1, since 0 would be first element
      ?'searched through $numelements elements. Did not find a match'
    ELSE
      ?'The '+numsuf($result)+' element (of $numelements) matches!'
    ENDIF
    $numbers=0,1,2,3,4,5,6,7,8,9,10
    $result=AScan($numbers,7)
    
     
    Source
    FUNCTION AScan ($array, $expr, OPTIONAL $expn1, OPTIONAL $expn2)
      DIM $element, $index
      $ascan=-1
      IF VarType($expn1) = 0 ;(not defined)
        $expn1=0
      ENDIF
      IF VarType($expn2) = 0 ;(not defined)
        $expn2=UBound($array)
      ENDIF
      IF ($expn1 >= $expn2)
        RETURN
      ENDIF
    
      $index=0
      FOR EACH $element IN $array
        IF ($element = $expr) AND ($index >= $expn1) AND ($index <= $expn2)
          $ascan=$index
          RETURN
        ENDIF
        $index=$index+1
      NEXT
    ENDFUNCTION ; - AScan -
     
      original source of UDF topic. show actual FunctionLibrary list on Scriptlogic site close top
              printer-friendly mirror of UDF topic on scripting@wanadoo.nl site  




    Copyright © 2003 www.scriptlogic.com & scripting@wanadoo.nl - last updated on 20 May 2003


    Site Meter