TinyDB CSV Export issues

Hi, I have the start of an app that enables me to scan a QR Code and store the data in a list, then export to local storage on Android as a CSV file.

The issue I'm having, is that each line in the list that is exported into the CSV, starts and ends with " (inverted commas) which prevents the data from appearing in columns.

Is there a way I can get the data to export without the "?

Please show us a screenshot of your relevant blocks including a Do it result of your data

Use the companion app and Do it to debug your blocks, see also tip 4 here App Inventor: How to Learn | Pura Vida Apps
see also Live Development, Testing, and Debugging Tools

Taifun


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

There is a text block to join a list with a separator character between items

Use \n as the separator.

\n is the New line character.

Thanks for the reply. I've attached the project here for ease block access

QRCodeLogger_UI.aia (4.0 KB)


I can't get a Do It result to show anything. I click Do It on the Export Blocks and the file is created on my phone but no data is shown on the PC screen

You are using two different tags to store your data:

  • an empty text (is this even legal?)
  • the fixed text value ',First Name,Last Name,Division' (That leading comma os probably trouble.)

You get from the blank tag, add new items to it, then store to the second tag.
So you lose whatever you had added on a previous run.

Then you loop through all the tags, assming each associated is a list with 1 item, to build an export text.

You write the text to a file, then try to read it back before it has finished the write operation. (look through the File events. They are there for a reason.)

I can't vouch for the /Download/ location. I prefer to use the share component for my exports.

Hi ABG,
Thank for the reply. That preceeding , has been removed. It was only there to see if it made a difference when opening the CSV file with Google Sheets (but it didn't).

The fixed text vale 'First Name,Last Name,Division' is there in the hope of adding Headers to the CSV file, which are required by the App I'm going to need to import the CSV into after all the works correctly.

The share component might be a better option in the long run, but I'm not sure the App I'll need to import to will support that.

Just trying to get a working CSV file before anything.
Thanks

Here's my redo using a single tag:


QRCodeLogger_UI (1).aia (3.3 KB)

I can't vouch for the file location /Download/

What I changed:

  • used a single constant tag for the list of scans
  • stuck to that tag for all my TinyDB work
  • avoided tag typos by using a constant global variable
  • delayed announcing file write success until its completion event
  • removed the read back code. It would have never worked in its location, and you've got TinyDB anyway.
  • used Create Empty List as the TinyDB Not Found default for the list of scans, avoiding poisoning of list operations with text blank where expecting a list.
  • rearranged the Clear button code sequence
1 Like

ABG Thank you. That fixes the issue and the CSV file is created and recognised properly. Thank you!

I'm going to compare the 2 aia files to try and get my head around the difference. Where was I tripping myself up with the tags? I'm sure I'll see when I compare.

Thank you ABG again

There are two philosophies regarding TinyDB storage of a list:

  • Everything under one tag
  • a tag/value for each item.

Each philosophy has its costs and benefits.

But NEVER mix them, like you did.

Noted. First time using TinyDB and it shows.

Appreciate the assistance and guidance ABG