Search code examples
androidlistbarcode-scannerapp-inventor

Program Flow AppInventor


Alright... No one laugh... I am working on an app in MIT/Google Appinventor. Here's a rundown:

  • Scans a barcode then runs the pictured function.
  • If the item is in the list then Find that items position index in the inventory list. Use that items index, to increment the value in the quantity list by 1.

  • If the item is not in the list then Add that item to the inventory, and add a "1" to the quantity.

I can't see why it won't work so I was just checking to see if there are any obvious flaws in my logic. If the logic looks solid, then I should be able to figure out the Appinventor problem to make it work.

enter image description here


Solution

  • Here's your function translated (accurately?) into pseudo-code to help with my own understanding (and hopefully others'):

    function addItem:
      if inventoryList.contains(scannerResult):
        inventoryPosition = inventoryList.positionOf(scannerResult)
        quantityPosition = quantityList.positionOf(scannerResult)
        quantityItem = quantityList.selectListItemAt(quantityPosition)
        quantityList.insert(quantityItem at inventoryPosition)
      else
        inventoryList.add(scannerResult)
        quantityList.add(1)
    

    The problem appears to be in the logic when the scanner result is already in the list. I don't know the relevant app-inventor functions, but I think that you want something more like:

      if inventoryList.contains(scannerResult):
        inventoryPosition = inventoryList.positionOf(scannerResult)
        quantity = quantityList.selectListItemAt(inventoryPosition)
        quantityList.setListItemAt(quantityPosition to quantity + 1)
    

    That last line is the bit I don't know how to translate into app-inventor language, but hopefully it's enough to point you in the right direction.