SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 4 of 4
  1. #1
    Member kiseta's Avatar
    Join Date
    Aug 2003
    Location
    Canada, Vancouver
    Posts
    66
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Question about CompareArraysNotOrder function

    The actual function posted at here and is quoted below.

    Question: Do the arrays have to be the same size? It does not seem to work if the size is different. I am comparing two arrays size of which is unknown and could be different. One array is a Standard and I need to find out if the array retrieved from the application has all the elements of the Standard. Also I need to see if anything is missing or there are any extra items. Screen shot of the data is attached.

    [ QUOTE ]
    This function compares two arrays and checks if they match but the order is not important

    (e.g. Actual Results vs Expected Results)
    <font class="small">Code:</font><hr /><pre> '**** Compare two arrays, the order of the data is not important ****


    Function CompareArraysNotOrder (arrArray1, arrArray2)

    Dim intArray1, intArray2

    For intArray1 = 1 to UBound (arrArray1)
    For intArray2 = 1 to UBound (arrArray2)
    If arrArray1 (intArray1) = arrArray2 (intArray2) Then
    arrArray1 (intArray1) = "MATCHED": arrArray2 (intArray2) = "MATCHED"
    Exit For
    End If
    Next
    Next

    CompareArraysNotOrder = True
    For intArray1 = 1 to UBound (arrArray1)
    If arrArray1 (intArray1) &lt;&gt; "MATCHED" Then
    CompareArraysNotOrder = False
    Exit For
    End If
    Next

    End Function</pre><hr />

    [/ QUOTE ]
    Attached Images Attached Images

  2. #2
    Moderator
    Join Date
    Jul 2005
    Location
    Delhi
    Posts
    15,575
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    7 Thread(s)
    Total Downloaded
    0

    Re: Question about CompareArraysNotOrder function

    When you see that code is running two loops with UBound on both arrays, that means the code does not assumed the arrays to be of same size.

    Between, the function would fail in such a scenario where
    intArray1 = Array(1,3,5)
    intArray2 = Array(3,3,1,1,5,5)

    [ QUOTE ]

    Also I need to see if anything is missing or there are any extra items


    [/ QUOTE ]
    You need to understand how the above code is working. Looking at your first question only i doubt that you understand how code is working. You should first study and the you would be able to solve your problem yourself. Comeup with some code that you think can do what you want to do and then if that has some issues then post that and we will try and resolve. The above code gives you a good direction on where to start and how to start.

  3. #3
    Senior Member
    Join Date
    Mar 2006
    Location
    Bristol, UK
    Posts
    1,530
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Question about CompareArraysNotOrder function

    I wote this function I while ago and I can I see a few little problems, oops!

  4. #4
    Member kiseta's Avatar
    Join Date
    Aug 2003
    Location
    Canada, Vancouver
    Posts
    66
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Question about CompareArraysNotOrder function

    You suggested to repost my question, so I did, but it does not mean that I have not tried to find a solution.

    Below is what I came up with. I understand that it is not perfect and it won't take care of the situation you suggested such as duplicate items but it works for my data (where items never repeat)
    <font class="small">Code:</font><hr /><pre>
    Dim arrStandard(11), arrCompareToStandard(12)
    arrStandard(0) = "Consumer Care Agent"
    arrStandard(1) = "Softphone User"
    arrStandard(2) = "CARE Level 0"
    arrStandard(3) = "OE-Admin Agent"
    arrStandard(4) = "Form Letter Collections Admin"
    arrStandard(5) = "Form Letter Order Entry Admin"
    arrStandard(6) = "Form Letter Billing Admin"
    arrStandard(7) = "Form Letter Admin"
    arrStandard(8) = "Form Letter Care Admin"
    arrStandard(9) = "Form Letter Client Portal Admin"
    arrStandard(10) = "Form Letter Credit Admin"
    arrStandard(11) = "Reference ODS Admin"

    arrCompareToStandard(0) = "Management and Professional Team"
    arrCompareToStandard(1) = "CARE Level 0"
    arrCompareToStandard(2) = "SP8"
    arrCompareToStandard(3) = "Form Letter Collections Admin"
    arrCompareToStandard(4) = "Form Letter Order Entry Admin"
    arrCompareToStandard(5) = "Form Letter Billing Admin"
    arrCompareToStandard(6) = "Reference ODS Admin"
    arrCompareToStandard(7) = "Consumer Care Agent"
    arrCompareToStandard(8) = "Softphone User"
    arrCompareToStandard(9) = "Form Letter Admin"
    arrCompareToStandard(10) = "Form Letter Care Admin"
    arrCompareToStandard(11) = "Form Letter Client Portal Admin"
    arrCompareToStandard(12) = "Form Letter Credit Admin"

    Function CompareArrays(arr1,arr2)

    For i = 0 To Ubound(arr2)

    Unique = True

    For j = 0 To Ubound(arr1)
    If arr1(j) = arr2(i) Then
    Unique = False
    Exit For
    End If
    Next

    If Unique then
    strDiff = strDiff &amp; arr2(i) &amp; ";"
    end if

    Next
    CompareArrays = strDiff
    End Function

    msgbox "Extra Items in arrCompareToStandard Array: " _
    &amp; CompareArrays(arrStandard,arrCompareToStandard) &amp; vbLf _
    &amp; "Missing Items in arrCompareToStandard Array: " _
    &amp; CompareArrays(arrCompareToStandard,arrStandard)
    </pre><hr />

    [ QUOTE ]
    When you see that code is running two loops with UBound on both arrays, that means the code does not assume the arrays to be of the same size.

    Between, the function would fail in such a scenario where
    intArray1 = Array(1,3,5)
    intArray2 = Array(3,3,1,1,5,5)

    [ QUOTE ]

    Also I need to see if anything is missing or there are any extra items


    [/ QUOTE ]
    You need to understand how the above code is working. Looking at your first question only i doubt that you understand how code is working. You should first study and the you would be able to solve your problem yourself. Come up with some code that you think can do what you want to do and then if that has some issues then post that and we will try and resolve. The above code gives you a good direction on where to start and how to start.

    [/ QUOTE ]

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 11.11%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 02:34 AM.

Copyright BetaSoft Inc.