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

Hi ABG,

Thank you again for you help the other night. Much appreciated!
I'm now trying to have a screen where data can be manually entered into a text box (hoping to be textboxes once 1 in working), and then store that data into TinyDB, so that when switching back to Screen1, the data is in the list and able to be exported.

I've tried for hours, trying to find content on this to assist, but I just can't put anything together that remotely works. Could I please pick your brain again?

QRCodeLogger_UI_1.aia (5.0 KB)

Before going further, I need to know what's arriving after the QR code scan is done.

Is it just a long number or code, or is there extra data in it?

Show a couple of examples.

Thank you for the reply.

I'm hoping to be able to add data from both sources, either the QR code scan, and/or on Screen2, manual entry textboxes

The QR Code data is First Name, Last Name, Division
and the manual entry textboxes will be the same data

Eventually I'd like to add more data to the CSV, but starting with these 3 options is ample for now.

What kind of problem is this app supposed to solve?

It's creating a CSV file of data that can be imported into a registration list of another app that doesn't support QR Code scanning, and has a confusing and messy UI for some older generations to fill out.

I'm trying to make the registration process for them as simple as possible. QR Code scanning is perfect for them, but I know sometimes they'll forget their card with the QR printed on it, so basic, non-messy manual registration on Screen2 would be their backup. Like when face recognition on my phone doesn't work, i can still enter my PIN

This way, I can have them register, via QR or manually, then I can export to CSV, and import into the required app

Here's one way to do it:

no_qr Designer:


no_qr
The concatenation is returned at close screen, and Screen1 is wired to look for it when this screen is closed:

QRCodeLogger_UI_1 (1).aia (6.1 KB)

I insert at item 1, for feedback.

P.S. I did not bother to check for embedded commas in the names, that would foul up later parsing ("Bond, James Bond"). A text replace comma with empty text would fix that.

:heart: Thank you ABG. I would never have thought to use the 'otherscreenclosed' controls. I've never seen that in any example results.

That definately does the trick and exports the same as data sourced from a QR Code scan.

Thank you for your knowledge and assistance once more. Appreciated!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.