Question

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

Was it helpful?

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.

OTHER TIPS

@blahdiblah made a good analysis of the problem.
The solution with App Inventor looks like this:
instead of the insert list item block you have to use the replace list item block

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top