Ömer Kılan

unread,
Jan 30, 2019, 1:02:22 PM1/30/19
to MIT App Inventor Forum
Hello, forum members, I'm trying to do a programming, but I did not know exactly which blocks to use. I don't want to use buttons to calculate. There are a lot of fruits, but I wrote three examples.

What I want to do is to calculate the automatic result of how many kilograms are entered for the apple. I think I can do this if the values are entered respectively or the values are all entered. But how do I calculate when the kilogram values are entered for randomly different fruits? Or when some fruits are left empty? It also calculates the result when the kilogram price is changed.

Should I use the "when ... lostfocus" block? I'd be very grateful if anyone could do a simple example.
automaticcalc.jpg

Taifun

unread,
Jan 30, 2019, 2:00:14 PM1/30/19
to MIT App Inventor Forum
you might want to use the textbox extension and its AfterTextChanged event to do your calculation

Taifun

Trying to push the limits of App Inventor! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.        

Ömer Kılan

unread,
Jan 30, 2019, 2:26:56 PM1/30/19
to MIT App Inventor Forum
Taif, thank you for your interest. I downloaded the plug-in immediately tried to try. But I couldn't, could you make a short example, Taifun? :(


textbox.jpg

Taifun

unread,
Jan 30, 2019, 2:48:43 PM1/30/19
to mitappinv...@googlegroups.com
what about downloading the example project to learn how to use the blocks?
also don't forget to use the StartTextChangedListener method...

Taifun

Ömer Kılan

unread,
Jan 30, 2019, 3:20:43 PM1/30/19
to mitappinv...@googlegroups.com
I downloaded the "Aia" file. I tried it on my phone and it works just fine. "StartTextChangedListener" worked with the moment but the mathematical problem arose.I'm trying to do mathematical calculation, I'm getting emty strings error. If the text box is empty, how do we perform a calculation such as no calculation for that row? I thought about using the "is empty" block here, but would it be a little long work for too many products?

For example, the number of kilograms for cherry is not entered, will not calculate the row of cherries.


starttext.png
errorempty.png

TimAI2

unread,
Jan 30, 2019, 6:47:57 PM1/30/19
to MIT App Inventor Forum
You could also try using a clock timer to automate the calculations (but the textbox extension method is more intuitive)

You blocks image doesn't help to show the calculations you are trying to do? From your designer screenshot it doesn't look that complicated.....multiply the rows then sum the totals ?

TimAI2

unread,
Jan 30, 2019, 6:49:01 PM1/30/19
to MIT App Inventor Forum
Also, your screen switching may need some work:

Use different screens wisely

If you decided to use different screens, then you should switch them correctly, else you will run out of memory after a while...      
The recommended method of switching screens in App Inventor
(Thanks Taifun)

Also see demo: multiscreen.aia

If you haven't done it already....

ABG

unread,
Jan 30, 2019, 8:25:52 PM1/30/19
to MIT App Inventor Forum
Your record keeping problem is to fruits as
this example is to player scores,
but this sample does not require you to change the program
structure every time you get a new type of fruit.

ABG

Ömer Kılan

unread,
Jan 30, 2019, 11:55:01 PM1/30/19
to mitappinv...@googlegroups.com
TimA2;

I'm using a single-screen single-screen as you can see in the image I added. And this is not an operation between screens. Only the lines will multiply and sum. So "(apple1 * appleP) + (cherry1 * CherryP) + (pear1 * PearP)" what does this have to do with the screen?

My problem is that it doesn't delete the number in the text box and gives an error. Or if I fill the 1st and 3rd text boxes, I get the error again if the 2nd text box is empty.

Ömer Kılan

unread,
Jan 31, 2019, 12:02:43 AM1/31/19
to MIT App Inventor Forum
ABG;

I examined your document from top to bottom, bottom-up. But I didn't find any resemblance. I will write the fruits manually. The user will fill the text boxes in these fruit lines. That's it.

I used Taifun's extensions "https://puravidaapps.com/textbox.php" ("AfterTextChanged"). However, when the text in the text box is deleted, it still returns an error. Or I get the error again when the text box in one of the lines is empty.

Ömer Kılan

unread,
Jan 31, 2019, 1:38:07 AM1/31/19
to MIT App Inventor Forum
I think I solved the problem. But there are too many fruits for these blocks will be too much. Looks like there will be lots of variables.
sumai2.jpg

Taifun

unread,
Jan 31, 2019, 8:15:09 AM1/31/19
to MIT App Inventor Forum
before doing a calculation, make sure to check for empty strings
also you might want to learn how to use procedures to simplify our blocks...

DRY - Don't repeat yourself

Taifun

ABG

unread,
Jan 31, 2019, 9:05:09 AM1/31/19
to MIT App Inventor Forum
It's not about the screens.

It's about the lists and the lists of lists.

Once you are more comfortable with lists
and tables, you will see a way to generalize this
to any collection of items, in a small number of components.

ABG

TimAI2

unread,
Jan 31, 2019, 10:25:14 AM1/31/19
to MIT App Inventor Forum
Just for fun, I have made up a little example using listviews and notifiers

screenfruits.png


autocalc.aia

Ömer Kılan

unread,
Jan 31, 2019, 11:50:51 AM1/31/19
to MIT App Inventor Forum
TimA2 ;

It's great.I've created too many text boxes and variables. You did it without adding a text box. If I can solve the listing event, I will learn a lot in "appinventor" :) It's a great work, you can add and delete it here. It is super user-controlled. Thank you so much. :)


Ömer Kılan

unread,
Jan 31, 2019, 11:56:34 AM1/31/19
to MIT App Inventor Forum
ABG;

Yeah, I'm going to have to solve this listing thing. It seems a bit complicated for me right now. Actually I can do it simply, but I can't list advanced. 

Ömer Kılan

unread,
Jan 31, 2019, 12:04:45 PM1/31/19
to MIT App Inventor Forum
Taifun

I actually used the procedures. I'm doing that stage, but I think I need information in the listing and variables merge phase. 

ABG

unread,
Jan 31, 2019, 1:40:32 PM1/31/19
to mitappinv...@googlegroups.com
Here's an uglier but more flexible approach,
suitable for hundreds of fruit types.

(I am having temporary emulator connect problems,
but it is stable enough to try ...

ABG

TinyDB_Purchases.PNG
Capture.PNG
Current Purchases List Picker.PNG
Setting Cackle Fruit Price.PNG
blocks.png
Fruit_Stand.aia
Menu options.PNG
Products.PNG
Startup.PNG
TinyDB_Prices.PNG
Cackle Fruit Corrected.PNG
Cackle Fruit correction.PNG

Ömer Kılan

unread,
Jan 31, 2019, 2:11:53 PM1/31/19
to MIT App Inventor Forum
ABG;

I tried it on my phone. It worked smoothly. Nice work. When I examined the blocks used, I learned very useful blocks. Especially this block. (if is number"txbUnitPrice.txt"  then "txbUnitPrice" else "0") . I'm adding a lot of blocks to say if it's not a number. I learned something.

Thank you ABG .
Reply all
Reply to author
Forward
0 new messages