Help w/ Comparing Two Multidimensional Arrays

Author Message
webspyder

  • Total Posts : 6
  • Scores: 0
  • Reward points : 0
  • Joined: 8/30/2011
  • Status: offline
Help w/ Comparing Two Multidimensional Arrays Tuesday, August 30, 2011 3:24 AM (permalink)
0
Hi guys, I have been stumped for a few days and have googled the heck out of my problem and have given up and need help.
 
I'm trying to populate a combobox by comparing two multidimensional arrays that have different subscript ranges.
 
My first array has all sizes in a table
ex: array1 [
{"InventorySizeId": 1, "InventorySizeName": "small"},
{"InventorySizeId": 2, "InventorySizeName": "medium"},
{"InventorySizeId": 3, "InventorySizeName": "large"}
]
 
My second array has only the sizes within a certain item
ex: array2 [
{"InventorySizeId": 1, "InventorySizeName": "medium"},
{"InventorySizeId": 2, "InventorySizeName": "large"}
]
 
I need help looping through both arrays, comparing, and displaying the items in array1 that dont match array2.
 
pseudocode:
for i=0 To Ubound(array1, 2)
for s=0 To Ubound(array2, 2)
       if i <> s then
           call function that creates a json object
       exit for
     end if
    next
next
 
I think I'm really close, but I don't know. Any help would be appreciated. Thanks!
 
#1
    ebgreen

    • Total Posts : 8227
    • Scores: 98
    • Reward points : 0
    • Joined: 7/12/2005
    • Status: offline
    Re:Help w/ Comparing Two Multidimensional Arrays Tuesday, August 30, 2011 3:45 AM (permalink)
    0
    So just to be clear, you want to do this in VBScript?
    "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
    Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
    http://www.visualbasicscript.com/m_47117/tm.htm
     
    #2
      webspyder

      • Total Posts : 6
      • Scores: 0
      • Reward points : 0
      • Joined: 8/30/2011
      • Status: offline
      Re:Help w/ Comparing Two Multidimensional Arrays Tuesday, August 30, 2011 3:49 AM (permalink)
      0
      Yes I think everything is good except for my if statement. How do I check the items of each array statement?
       
      #3
        ebgreen

        • Total Posts : 8227
        • Scores: 98
        • Reward points : 0
        • Joined: 7/12/2005
        • Status: offline
        Re:Help w/ Comparing Two Multidimensional Arrays Tuesday, August 30, 2011 3:57 AM (permalink)
        0
        first I have a couple of questions:
         
        What consitutes a match? Do both parts have to be the same (ID and Name)? Or would the same name existing in each array with different IDs still count as matching?
         
        Do you control the way these arrays are built? If you do then I suspect that a dictionary would not only make the comparison easier, it would make the data easier to work with.
        "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
        Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
        http://www.visualbasicscript.com/m_47117/tm.htm
         
        #4
          webspyder

          • Total Posts : 6
          • Scores: 0
          • Reward points : 0
          • Joined: 8/30/2011
          • Status: offline
          Re:Help w/ Comparing Two Multidimensional Arrays Tuesday, August 30, 2011 5:23 AM (permalink)
          0
          I'm grabbing these recordsets from sql and all sizes have a unique id so really I can just compare the first part, second or whole it doesn't really matter because no value will have the same id or name.
           
          #5
            ebgreen

            • Total Posts : 8227
            • Scores: 98
            • Reward points : 0
            • Joined: 7/12/2005
            • Status: offline
            Re:Help w/ Comparing Two Multidimensional Arrays Tuesday, August 30, 2011 6:05 AM (permalink)
            0
            So do you have an array or a recordset? Which one? Also, if you are executing a query to generate the data, why not get the correct list with the query? SQL is much better at this than an algorithm that you write after the fact would be.
            "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
            Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
            http://www.visualbasicscript.com/m_47117/tm.htm
             
            #6
              webspyder

              • Total Posts : 6
              • Scores: 0
              • Reward points : 0
              • Joined: 8/30/2011
              • Status: offline
              Re:Help w/ Comparing Two Multidimensional Arrays Tuesday, August 30, 2011 6:33 AM (permalink)
              0
              I am making two database hits with two seperate function calls and returning 2 recordsets as 2 seperate arrays.
               
              I have an associate table( tblSizeChart ) that is connected with a 2 foreign keys to 2 seperate look up tables, which is lutItem and lutSize.
               
              So the first array has a recordset( select sizeId, sizeName from lutSize ) and the second array has ( select sizeId, sizeName from tblSizeChart where itemId = ? )
               
              I'm trying to populate a combobox with only the sizes that aren't already being associated with a certain item.
               
              I hope this helps. Would there be some kind of sql statement that would be faster to get this information, instead of looping through two arrays?
              <message edited by webspyder on Tuesday, August 30, 2011 6:35 AM>
               
              #7
                ebgreen

                • Total Posts : 8227
                • Scores: 98
                • Reward points : 0
                • Joined: 7/12/2005
                • Status: offline
                Re:Help w/ Comparing Two Multidimensional Arrays Tuesday, August 30, 2011 6:49 AM (permalink)
                0
                Yes, doing it in SQL would be a much preferable solution in my opinion. Something like:
                 
                SELECT lutSize.sizeID, lutSize.sizeName FROM lutSize WHERE NOT EXIST (SELECT tblSizeChart.sizeID FROM tblSizeChart WHERE lutSize.sizeID = tblSizeChart.sizeID)
                 
                I'm not a huge SQL person, but something along those lines should do what you want.
                "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
                Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
                http://www.visualbasicscript.com/m_47117/tm.htm
                 
                #8
                  webspyder

                  • Total Posts : 6
                  • Scores: 0
                  • Reward points : 0
                  • Joined: 8/30/2011
                  • Status: offline
                  Re:Help w/ Comparing Two Multidimensional Arrays Tuesday, August 30, 2011 7:06 AM (permalink)
                  0
                  Ok ya I think that would be a lot easier. I'm going to work with my query and see if I can pull the information that I need.
                   
                  #9
                    webspyder

                    • Total Posts : 6
                    • Scores: 0
                    • Reward points : 0
                    • Joined: 8/30/2011
                    • Status: offline
                    Re:Help w/ Comparing Two Multidimensional Arrays Tuesday, August 30, 2011 8:00 AM (permalink)
                    0
                    Ok I got the fix!!! SQL it is!
                     
                    select distinct sl.sizeId, sizeName from lutSize as ls
                    where ( select count( st.sizeId ) from tblSizeChart as st
                    where st.itemId = ? and sl.sizeId = st.sizeId ) = 0
                     
                    The (?) is the itemId that I pass in. THANKS ebgreen for all your help!!!
                     
                    #10
                      ebgreen

                      • Total Posts : 8227
                      • Scores: 98
                      • Reward points : 0
                      • Joined: 7/12/2005
                      • Status: offline
                      Re:Help w/ Comparing Two Multidimensional Arrays Tuesday, August 30, 2011 8:08 AM (permalink)
                      0
                      Glad you worked it out. It's an odd day when I answer something in the ASP section. Even odder if I get anywhere near to the right answer.
                      "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
                      Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
                      http://www.visualbasicscript.com/m_47117/tm.htm
                       
                      #11

                        Online Bookmarks Sharing: Share/Bookmark

                        Jump to:

                        Current active users

                        There are 0 members and 1 guests.

                        Icon Legend and Permission

                        • New Messages
                        • No New Messages
                        • Hot Topic w/ New Messages
                        • Hot Topic w/o New Messages
                        • Locked w/ New Messages
                        • Locked w/o New Messages
                        • Read Message
                        • Post New Thread
                        • Reply to message
                        • Post New Poll
                        • Submit Vote
                        • Post reward post
                        • Delete my own posts
                        • Delete my own threads
                        • Rate post

                        2000-2012 ASPPlayground.NET Forum Version 3.9