scripting@wanadoo.nl




JoinArray()

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 close
31 May 2002 JoinArray()
AuthorLee Wilmott
Action Joins two arrays together. Also allows the adding of elements to an array.
SyntaxJoinArray ("firstarray", "secondarray") 
Parameters
  • firstarray (Required / Array) An array of any size.
  • secondarray (Required / String) An array of any size. 
  • RemarksI've updated this function to allow an array to be appended to an empty array (and vice versa), it makes the function a little more complex but more useful.
    Note that this function can be used to add elements to the beginning or the end of an array.
    I personally use this function a great deal. If you think you would find it helpful please make a comment - you never know, maybe Ruud will add it to the final release!!! 
    ReturnsA larger single array containing both the first array followed by the second array. 
    DependenciesNone. 
    Examples
    $FirstArray = "one", "two", "three"
    $SecondArray = "four", "five", "six"
    
    $BothArrays = JoinArray($FirstArray, $SecondArray)
       To Return: "one", "two", "three", "four", "five", "six"
    ---------------------------------
    
    $FirstArray = 1, 2, 3
    $SecondArray = 4, 5, 6
    
    $BothArrays = JoinArray($FirstArray, $SecondArray)
       To Return: 1, 2, 3, 4, 5, 6
    ---------------------------------
    Other Examples
    
    $AnArray = "one", "two", "three"
    
    $BothArrays = JoinArray("something", $AnArray)
        To Return: "something", "one", "two", "three"
    
    $BothArrays = JoinArray($AnArray, "somethingelse")
        To Return: "one", "two", "three", "somethingelse"
    
    $BothArrays = JoinArray("one", "two")
        To Return: "one", "two"
    
     
    Source
    FUNCTION JoinArray ($firstarray, $secondarray)
      ;This function concatenates two arrays.  The second array follows the first.
      DIM $element
      REDIM $newarray
      REDIM $firstrealarray, $secondrealarray
    
      IF VarType($firstarray) > 0 AND VarType($firstarray) < 8192  ;if the first array isn't an array
        REDIM $firstrealarray[0]             ;then turn it into one
        $firstrealarray[0]=$firstarray
      ELSE
        $firstrealarray=$firstarray
      ENDIF
      IF VarType($secondarray) > 0 AND VarType($secondarray) < 8192  ;if the second array isn't an array
        REDIM $secondrealarray[0]            ;then turn it into one
        $secondrealarray[0]=$secondarray
      ELSE
        $secondrealarray=$secondarray
      ENDIF
    
      IF VarType($firstrealarray) = 0 AND VarType($secondrealarray) = 0 ;if first and second array are empty
        $newarray=$firstrealarray            ;return empty
      ELSE
        IF VarType($firstrealarray) = 0      ;if the first array is empty
          $newarray=$secondrealarray         ;return second array
        ELSE
          IF VarType($secondrealarray) = 0   ;if the second array is empty
            $newarray=$firstrealarray        ;return first array
          ELSE
            ;otherwise
            $newarray=$firstrealarray        ;append second array to the first
    
            FOR EACH $element IN $secondrealarray
              REDIM PRESERVE $newarray[(UBound($newarray)+1)]
    
              $newarray[UBound($newarray)]=$element
            NEXT
          ENDIF
        ENDIF
      ENDIF
      $joinarray=$newarray
    ENDFUNCTION ; - JoinArray -
     
      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