2014년 11월 29일 토요일

updating a table


When updating my table where some values were stored at the time of creation and some were left blank and later I want to store something in the blank ones do I just use Call TinyDB.storeValue and just write over whatever is there blank or not or do I need to use a replace block?  For example when I create this table one of the fields left blank is Spec_Sales_AmtLabel9 later on I may want to update that field 3 or 4 times adding more sales to whatever is store there.  Do I just store the new value or do I use a replace block?


--
When you store data to a TinyDB tag it will simply overwrite whatever is there.  Similarly the Replace block for a list will replace the specified (by index number) value in a specified (by name) list. When dealing with a list you need to use the replace list item block. When updating the TinyDB call .StoreValue

As you've shown the data stored in a TinyDB tag can be number, text, list, timeinstant, or even a component. if you're updating a value in a list that is stored in a TinyDB then you need to replace the list item, then call the StoreValue to update the list in your TinyDB tag.

Clear as mud? :)

--
Okay yes I am still a little confused.  Are there any of the tutorials that deal with the replace bock or show me an example using the structure in my first post? 

Does this look right I'm trying to add IE update the value stored in Spec_Sale_AmtLabel9?

--
Looks like you're on the right track but a little mixed up. 

In that first GetValue block the valueIfTagNotThere should be a 10 item list not '0'. Otherwise you'll try to select list item from a number value. This will throw an error. If the TinyDB1 tag is a list then you're setting a ..._Label9 to the 10th item in the list. So far so good. You then add Amt_Purchased.Text to the ..._Lable9.

Next you call a StoreValue to save a list to the tag named in the SpecialLocationTxtBx. Dealing with just ..._Label9  you have now added Amt_Purchased to it and resaved it to a different tag unless SpecialLocationTxtBx is equal to List_SpecialLocation.Selection. In which case you'll have overwritten the same tag with the new values but I can't tell from just this bit...

Your replace list item replaces an item in the global locationList with Spec_Sale_Amt_Lablel9.txt  The list item replaced is whichever item is selected in List_SpecialLocations.  Is there any reason to be certain that's the 10th item?  What is stored in global locationList?  Locations or location data?

The last block showing stores the above list to the tag 'locationList'. 

So...

Your retrieving a value from a list stored in one tag, changing it, then storing a list including the updated value, to a, possibly new, tag. You've then replaced what looks like a location name in a list of location names with this updated numerical value and stored that list as 'locationList'  I doubt that's what you want to do.

The pattern you probably want is
1. Get a tag that contains a list into a variable (typically a global) - GetValue
2. Replace list items as required. - replace list item
3. Store the list to the tag. - StoreValue

You can do this in separate places or even all at once. You can select a specific item from a list after getting the tag as you've done in that first block. However, you can't replace a list item in a TinyDB tag, even if that tag contains a list. i.e. you have to store the entire tag all at once. So, if you want to store a list you have to store an entire list.

--
Like so.


Although I s'pose you could StoreValue a list using the make a list in which each list element is selected from a list which is returned from a GetValue but there's no point to it.

--
Hi Greg, thank you so much for your input.

I am still having fits and spurts trying to figure out exactly how to access my data structure.  At the end of the quarter I want to run a report and go thru each item in the list but I use a block like the one below I get Bad arguments to select list item The operation select list item cannot accept the arguments: Courion 2  -------  Courion is the first location in my locationList tag and global locationList and 2 is the position of the data I need at this point.  To the right is a partial of my runReportBtn  and then another partial down to the point where it blows up IE gives the error.  Plus It doesn't really go thru each item in the list well It does get each location but the data values are all the same and only equal to the data values of the last item selected from the list picker.  I want the user to be able to run the report with out selecting each location from the listpicker




--
List handling in AI is going to give you fits until you get some practice.  When in doubt simplify. I discarded an app with dozens (and dozens) of hours invested because my lists got too complex for me to wrap my own head around.  I restarted with a simpler structure.  

The Bad Arguments error indicates that one of the arguments (the list your selecting from or the index number) is not what it needs to be.  Either you're trying to select a list item from something that is not a list, or the index is not a number. Since cnt is likely a number, and '2' certainly is, then the list in "locationList" is not a list of lists. Certainly it's not if the getValue returns the simple Empty list. You would at minimum need to use MakeList and have at least one item within it which is also a list.  

The loop in runReportBtn assigns a result to the Global "listOfValues" each time through. Thus each time through the loop it reassigns a new value to listOfValues until it gets to the end.  Try instead ADDing the result to what is already in listOfValues. If you want listOfValues to be an actual list then you need to use 'add items to list'. When you dump the list into the label to show it (which you might want to do below the loop) you'll see the list. It'll probably need some formatting with the text blocks and more looping.

Also... if I may offer some thoughts...OK... an opinion and please ignore it if it is way out of touch with what you're actually trying to do. 
re: " At the end of the quarter I want to run a report..."  This is very classic thing to do with minicomputers, chain printers and boxes of  tractor feed paper.  It may not be a useful type of thing to do with a smartphone or tablet with a connection to 'the cloud'. Think about what experience/information your user needs and how it can best be presented. The answer may not be 'an app'. One of the most fun things about App Inventor, and building apps in general, is rethinking these classic problems. What is REALLY needed by your user. It's likely they don't fully understand the problem themselves. Instead of trying to 'run a report' can you give your user just the information they want, whenever they want, the way they want? Don't create a report... create an experience.

--

댓글 없음:

댓글 쓰기