2017년 4월 2일 일요일

TinyDB help please


Is there anyway to have data PRE STORED in a TinyDB when an application starts for first time?

The database held will be a list of names and stats for a baseball player. These do not change at any time.

i can write blocks so when a name is generate it is then saved in the TinyDB while the application is open but not so Data is already there when the application opens for the first time.

--
"Is there anyway to have data PRE STORED in a TinyDB when an application starts for first time?"   No.  Prefilling a TinyDB is not possible.   A predetermined csv file can contain the same information.       "Babe Ruth", 714,2873,2213,2.28         where    name,Hr,Hits,RBJI,ERA   is the sequence.     Access the info with the File component.

 Put the names and stats in a csv text file.  The csv can be hard coded using blocks or saved as a resourse in Media easily.  You can read the csv from the sdCard, however that is not what you want to do.   If the stats must be in the TinyDb, load the csv data to the TinyDB on first run of the app either with the File control or it might already be there if you load it as a resource.

Depending on what your app does, you could retrieve and store the stats in the csv file  instead of in the TinyDB.      

--
Second time writing this, lets see if it posts this time!!! :0

I did consider the CSV idea however the blocks is where i fell down and couldnt find a solution. 
The CSV was created in excel and has 10 columns and around 50 rows so far.

i can do the blocks to find the file and read it but then it breaks down and i get lost.
what i want it to do is as an example find the name in column one "babe ruth" and the then populate certain labels with data from his row

Make sense?

--
i can do the blocks to find the file and read it but then it breaks down and i get lost.
It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

you also might want to learn how to work with lists
⦁ How to work with Lists by Saj
⦁ How to work with Lists and Lists of lists (pdf) by appinventor.org

this also can help: how does a list of lists (2 dimensions) look like

--
i cleared the one i did previous so created quick one to show u the blocks i am up to and the details on side panel,

From my understanding them blocks tell on screen start up to change a text label to entry in the TDB and then to call the CSV file.
From here i am stuck...

-- 
as already recommended, learn how to work with lists, you will need it...


-- 
I understand how to create a list, how to use the spinner and seclection.

I understand the result command also that once it is read it will come back with a result,

What i dont get is the next step which is saving that result back as a table that is searchable.

-- 
ok i have now managed to get to here.

The csv is read and the result is added the the list. However not as i wanted.  i have added the Do it comment too.
It found right hook which is correct but when read the CSV also contains a description in the next column and a damage number.


-- 
what i want it to do is as an example find the name in column one "babe ruth" and the then populate certain labels with data from his row
after importing the csv table into a list of lists you will have to create 2 lists: a list which contains only the first column of the table and a list of lists, which contains all other information

Now you can use the index in list block to get the index of "babe ruth" from list1, then use the select list item block to select all the corresponding information from the list of lists

you might want to learn how to work with lists, then try something and if you get stuck, post again here with a screenshot of your relevant blocks

--
This example uses only csv files loaded to Media 9resources.)  It might provide you with some ideas.

The ListView has a search capability which unfortunately is BROKEN, so don't even try.   You can place all your player names in the list view.  Two ways of handling the data are shown.  Build the app and experiment and use the pieces you need.    



--
Thank you so much that was very very useful. I am trying to perfect this on the wrestling app i was working on at the moment and can now get to the point where reads the CSV files and is able to select a row based on index as number. Attached is the blocks and do it responses. i cannot see to get the last part working where it will display the reuslted rows as seperate entities.  ie pull first part of string in index 1 and change label to it, then index 2 and so forth. every permitation i have tried has failed.
Can you look at the attached and see how it looks to you. i have deleted the final blocks so i can add them.






--
Here's a doc with another example for you ...
Thank you for the link.

I have seen this doc before and still have trouble getting head around it.

--
What would help is to see what your csv file looks like  ..the rest of the block you are copying from...which you do not have in your code, displays the csv file.

I am going to guess part of your problem is that you do not have a space where the green circle is located ..perhaps you left it blank?     The second part is the issue could be how you made your csv file.   If the file comes from an Excel spreadsheet I have heard that Excell adds extra 'hidden' characters when it converts.   I do not have Excel so not the expert here; however, if your csv has extra hidden characters, that may be why the file is not displaying (the other reason is that you have to be connected to a device or an emulator for the DoIt to work.

--
The file was created in excel 2010.

The problem just to clarify is the  next step after where I am now (pics from last pos)

So far AI2:
- Finds both csv files.
- looks for as an example index 4 and pulls the row
- row is the placed in its own list
- the row displays on a label with open and close brackets.  There is 6 parts in the string and all are there.

What I need next is for the app to take that info and seperate the 6 onto individual labels

--
Wow you guys are good!! :D:D:D

it looks like it now working. i had missed the space but also hadnt got the split line in correctly. 

Will go from here and will post and let you know how i getting on.

--
The example shows how to separate into separate labels Gaz.    I think the problem is described here:  is in list error    but I do not know how someone gets rid of a BOM.     Sorry, I do not have excel ...I imagine you would use a fancy Notepad clone like Notepad ++   that can show hidden files and remove the BOM.

To get into labels, you probably need to fix the BOM issue   and then use the labe3 to label 7 part of the example code blocks (label8 outputs the info in a single string).

I would do this, redo the first two or three entries in you excel spread sheet, but make them in the form shown in the example... do not copy them, type them in Notepad.  Then, replace your current csv files with this shortened file and see what happens.

--

댓글 없음:

댓글 쓰기