Skip to first unread message

chrisvdh

unread,
Mar 18, 2019, 9:23:36 AM3/18/19
to MIT App Inventor Forum
Hi 

I am reading in a CSV file and encrypting each item in the row before writing to a new file.  So two loops 1 to total number of records and then from 1 to 12 (the number of items in each row).

I am getting strange results in that the sequence goes haywire at random!

so read in e.g. 
"1234; name; address; ano1; ano2"   quotes are not part of the data

then encrypt 

then write out encrypted data as "gfhf; ththththjdk; hjhsfkjhsk; ano1; ano2"

This on a file of around 360 rows.  Most appear correct but some appear with transposed data!

e.g. sometimes the app writes the following 

"gfhf; ththththjdk; hjhsfkjhsk; ano1; jhjh" (the next number) ano2 appears as the start of the next row.

Has someone encountered this sort of issue before?

TimAI2

unread,
Mar 18, 2019, 9:38:22 AM3/18/19
to MIT App Inventor Forum
We would need to see your blocks to identify what is going wrong

Right Click in Blocks Editor and select "Download Blocks as Image"
(use image editor to crop etc. if required)

or you can upload an aia file for someone to take a look at

Sounds like something is shifting in your loop, and either not encrypting, or adding an extra "1" somewhere

ABG

unread,
Mar 18, 2019, 10:40:43 AM3/18/19
to MIT App Inventor Forum
Also check  your incoming data file for uneven number of semicolons per line.

ABG

TimAI2

unread,
Mar 18, 2019, 10:52:27 AM3/18/19
to MIT App Inventor Forum
or colons...

chri...@mweb.co.za

unread,
Mar 18, 2019, 3:31:21 PM3/18/19
to MIT App Inventor Forum
Thanks guys.

The list functions do not like the incorrect number of fields (columns).  :) Seen a lot of error messages wile making the app. I use the input file within my other lookup app quite successfully.  It is only since trying to encrypt the fields that I get this weird transpose issue.
blocks.png

ABG

unread,
Mar 18, 2019, 4:47:02 PM3/18/19
to MIT App Inventor Forum
This would be much easier if you were to do the semicolon-to-comma replacement
before the csv table conversion.

Then you could build up a new table row by row, column by column,
and do the reverse csv table conversion in one shot,
before doing reverse coma->semicolon replacement in one shot,
then write it all out.

I attached a sample I used with another semicolon lover.

Also, your column limit should be length of list(row), not 12.
That would be more bulletproof.

ABG

blocks.png
Capture.PNG

chrisvdh

unread,
Mar 19, 2019, 4:31:18 AM3/19/19
to MIT App Inventor Forum
Thanks for the reply, but let's forget about the encryption and how I create the list.  It works for me.

The actual problem is the transposition of the fields in the row when WRITING to a text file.  When displaying the selected field then all works.  It is only on the write to a text file when things go wrong.  That is my issue.  I have spent the morning recreating this problem and include the blocks to prove it.

Maybe this is not the correct forum for this but I feel this is some kind of bug...?


file_write.png

chrisvdh

unread,
Mar 19, 2019, 5:23:07 AM3/19/19
to MIT App Inventor Forum
Further I have taken a small extract of the input file (36 records) and I run it 3 times with the same code and get three different result files.  Random transposition of the fields.

TimAI2

unread,
Mar 19, 2019, 6:32:32 AM3/19/19
to MIT App Inventor Forum
I may have over simplified things a bit but have put together an example which I hope will help.

If I understand correctly, you want to read in a csv file with the base data, encrypt each element, then output the encrypted version to a file ?

(To replicate your crypto function, I simply added an X to the beginning of each element)

My example is repeatable, meaning I get the same result each time.
I have included the clock timer to give the device time to write the file so it is there when called

aia project file attached

BLOCKS

blockscrypto.png




SCREEN

screencrypto.png


readencryptwrite.aia

chrisvdh

unread,
Mar 19, 2019, 9:27:38 AM3/19/19
to MIT App Inventor Forum
Thanks Tim, I reworked my code to use those "for list" blocks and have come right!  Many thanks.  
PS I moved away from the lovable semicolon.  lol.

ABG

unread,
Mar 19, 2019, 9:32:08 AM3/19/19
to MIT App Inventor Forum
I wonder if the File Append operation needs an 
Event block for completion, like the File Saved block?

Why should File Save take time, but
file Append be regarded as instantaneous?

I would imagine shooting off rapid fire Appends
might stack them up temporarily while they sort themselves out.

That's why I advocate for building up an in-memory table
and delaying File operation until
it's complete.

ABG

TimAI2

unread,
Mar 19, 2019, 9:53:56 AM3/19/19
to MIT App Inventor Forum
I only did it like that to show the data had been saved to the file correctly which was one of the OP's issues
Normally, one would just carry on with the output list in the app.
Reply all
Reply to author
Forward
0 new messages