none
Array organiser help RRS feed

  • Question

  • Hey there,

    I ran into a problem. This site has been very helpful for me as an (anonymous) browser in terms of tuts and what not. Watching old threads also helps. But now I ran into a problem;

    I want to make an program with arrays (I made some already) and they are pretty usefull. But I tried to make something to keep track of my supply at home.

    I figured I made this;

    'what do I need?

           tobuy[1]="bread"
    tobuy[2]="milk"
    tobuy[3]="eggs"
    'What do I already have?
    house[1]="crisps"
    house[2]="carrots"

    house[3]="milk"

    I tried something like this, but don't have any clue how to make this...;

    for a=1 To array.getitemcount(tobuy) 

    for b=1 to array.getitemcount(house)

    Save=tobuy[a]+house[b] Endfor Endfor 

    Now, I want to make some kind of a routine wherin it will compare those two lists and write down what I already have (milk).

    Is there anyone who wants to help me with this? Thanks in advance, sorry for my bad English, I'm not a native speaker.

      Cheers, :)
    Tuesday, June 16, 2015 4:50 PM

Answers

  • house = "1=crisps;2=carrots;3=milk;"
    tobuy = "1=bread;2=milk;3=eggs;"
    TextWindow.WriteLine("house: "+ house)
    TextWindow.WriteLine("tobuy: "+ tobuy)
    TextWindow.WriteLine("")
    
    For n = 1 To Array.GetItemCount(tobuy)
      If Array.ContainsValue(house, tobuy[n]) Then
        have[Array.GetItemCount(have)+1] = tobuy[n]
      Else
        get[Array.GetItemCount(get)+1] = tobuy[n]
      EndIf
    EndFor
    TextWindow.WriteLine("Have: "+ have)
    TextWindow.WriteLine("Get:  "+ get)

    Happy shopping!


    • Proposed as answer by Ezra94 Wednesday, June 17, 2015 6:40 PM
    • Marked as answer by WhTurner33Editor Sunday, June 21, 2015 9:45 AM
    Tuesday, June 16, 2015 6:15 PM
    Answerer