Return an Array that contains only the diffrent items from 2 arrays

Discussion in 'ASP General' started by Erv, Apr 26, 2007.

  1. Erv

    Erv Guest

    <%
    ' Return item that are NOT duplicated in either array
    function ShowDiff(array1, array2)
    dim d, item, thekeys, build_arr

    ' Build Array - a command that will be Execute
    build_arr = "anArray = ARRAY("

    ' Loop through the first array, add to output
    for x = lbound(array1) to ubound(array1)
    build_arr = build_arr & "array1(" & x & "), "
    next

    ' Loop through the second array, add to output
    for y = lbound(array2) to ubound(array2)
    build_arr = build_arr & "array2(" & y & "), "
    next

    ' Cleanup last comma
    build_arr = left(build_arr, len(build_arr) - 2)
    build_arr = build_arr & " )"

    ' Excute the build statement
    execute build_arr


    ' Show differences
    set d = CreateObject("Scripting.Dictionary")
    d.removeall
    d.CompareMode = 0
    for each item in anArray
    if not d.Exists(item) then
    d.Add item, item
    else
    d.Remove item
    end if
    next
    thekeys = d.keys
    set d = nothing
    ShowDiff = thekeys
    end function
    %>
     
    Erv, Apr 26, 2007
    #1
    1. Advertising

  2. Erv wrote:
    > <%
    > ' Return item that are NOT duplicated in either array
    > function ShowDiff(array1, array2)
    > dim d, item, thekeys, build_arr
    >
    > ' Build Array - a command that will be Execute
    > build_arr = "anArray = ARRAY("


    You expect us to embrace a script that uses Execute to execute a
    string???
    Give it some thought. I'm sure you can come up with a way to avoid
    Execute.

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Apr 26, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Dyer
    Replies:
    5
    Views:
    648
  2. Abs
    Replies:
    0
    Views:
    517
  3. Abs
    Replies:
    0
    Views:
    404
  4. Philipp
    Replies:
    21
    Views:
    1,133
    Philipp
    Jan 20, 2009
  5. Joshua Muheim
    Replies:
    8
    Views:
    196
    Dejan Dimic
    Nov 23, 2007
Loading...

Share This Page