Return value based on comparison from input to a table

Hello at all,

I need just a starting point or a hint if the Idea I have can be build inside the App w/o database.
Assume I have two input field for digits, e.g. 25 and 65 and a fixed 'table' with
20, 30, 50,
30, 40, 70,
A , B , C
Now, based if the '25' input lookup if all 3 values in line1 <=25 and jump from A to B, line2 <=.65 hence result must be C.

My understanding: the input 'input figures' need to be a variable that is insert into the comparison. But how to handle the 'table'??
Sorry, I hope it will be understandable.

Thank you in advance......

Is it always just 3 columns, or can there be more than 3 columns to search?
If just 3 columns, you could add an extra socket to the max() block and take

Set Label.Text to 'A'
for n = 1 to length(table)
  set row to item n of table
  if (max(
    select item 1 from row,
    select item 2 from row,
    select item 3 from row) > 50
  then set Label.Text to (select item 4 from row)
end for n

Come to think of it, are you looking for

  • a column of decision results to be set in the table, or
  • one final result (A/B/?) derived from walking the table?

Hello and thank you.
The source table must not be visible beside the A or B pick which should be displayed. So, one final result.

Startet now with a list in a list.......looked promising.

What would be the final result of the sample you posted, and why?

@ABG, see edited sample. Resut is C.

I droped some blocks to my APP but now I am running out of 'if' functions, see attached.screen1

The blue mutator buttons let you add more sockets. to blocks.

https://appinventor.mit.edu/explore/ai2/support/concepts/mutators

2 Likes

To give you a better sample I have put it in excel. Input fields are blue, result field is green.
The Excel formula in the green 'C' field is this one:
=IF(AND(C3<=C4,D3<=D4,E3<=E4,B3<=B4),F4,IF(AND(C3<=C5,D3<=D5,E3<=E5,B3<=B5),F5,IF(AND(C3<=C6,D3<=D6,E3<=E6,B3<=B6),F6,IF(AND(C3<=C7,D3<=D7,E3<=E7,B3<=B7),F7))))
table1

So I think my and loop is too short.

What happens if there is no match ?

For this case an alert msg is ok to 'reduce pcs QTY' or something like that.

Thank you for asking

Try this, seems to work OK

cartons.aia (4.4 KB)

1 Like

Hello, cool input. thank you.
I will try it this evening and add the input TextBox accordingly. :slight_smile:
Can I place the simultaneusly read of 3 or 4 TextBox'es on one Button.??

Yes, just make sure you do this before running any other part of the function. And set your textboxes to numbers only to reduce errors.

1 Like

I took @TimAI2's app and tried a function-based approach.

I am not satisfied with the OP's Excel formula or any of our solutions (mine included), if they ignore the possibility of putting multiple small pieces into a large carton.

This looks like an example of the packing problem, a well known math problem.

Capture Capture2 Capture3 carton_size_fitter.aia (5.1 KB)

1 Like

Sorry, I was a litte offline for a whlie. It is not the target to carculate mixed loads.
But your sample looks amazing.! I will copy it into MITapp and try to understand...