The Shopping demo stack is an attempt to push a MoStack in the direction of a "true" program, not only showing static data, but offering some "functionality".
The stack attempts to implement an electronic shopping list: For every item that you shop regularly you create a card with background Item. Each such item card has a Buy today? checkbox on it. Preparing a shopping trip, you go through all the items, decide for each one whether you want to buy it today, and if yes tick the checkbox and optionally adjust the number of items to buy.
The first card of the stack is the resulting shopping list. In a list field with 3 colums it shows all the items marked for today's shopping. Technically, the list is a so-called card list, showing cards of background Item, but not all of them, only the checked ones. MoStacks can generate and update this list automatically, without the help of complicated script programming, because card lists have a lot of configuration flexibility.
The Buy and the No Buy buttons help with the speedy checking and unchecking of the various items according to today's shopping needs. Behind the two buttons there are small scripts that set the # of pieces to 1, check or uncheck the buy mark and go right to the next card.
On Select Put "T" Into Field "Buy Today" Put 1 Into Field "Pieces" Go To Next Card End Select
The most complicated script is the one behind the Calc button on the shopping list card which calculates the total pay for all selected items, taking their prices and the # of pieces to buy into account.
On Select total=0 Repeat For Each Card c Of Background "Item" If Field "Buy Today" Of Card c Then total=total+(Field "Pieces" Of Card c)*(Field "Price" Of Card c) End If End Repeat Put total Into Field "Total" Of Card "Shopping List" End Select