Renumbering ID numbers in lists

Hi all, I have created a small app that I practice TinyDB for a bigger project I am planning to start on once I've sorted out a few problems with TinyDB.

This is my first problem that I have not been able to figure out and can't find any info on how to do anywhere. I hope I can explain it

I have 6 textboxes, firs is "name.TxtBox" which is used as the tag to store the data in the other 5 textboxes. The second is an ID number that gets generated automatically starting from 1 in increaments of 1. This all works good so far but the problem is when I delete an entry.

The list looks something like this:

name1,1,30,40,50,60
name2,2,20,25,46,78
name,3,3,45,56,46

If I delete number one, I am left with the ID numbers 2 and 3.

What I'd like to do is renumber the IDs still in TinyDB starting from one again.

ie:
change name2,2,20,25,46,78 to name2,1,20,25,46,78

change name,3,3,45,56,46 to name,3,2,45,56,46

Is this possible?

TIA

Eric

Why not save items to a list, then save the list to a tinydb ? You then only have one tag to worry about, and load the list when the app starts from tinydb.

You can then use the item index in the list when you add or delete items.

Your use of the local variable blocks seems a little unnecessary, plus you don't appear to have found the mutator to add variables to the first block ?

Something like this:

1 Like

with delete

1 Like

Thanks for the reply.

I have never tried using a list, no idea how to TBH. I will give it a go and see if I get anywhere with it

I used the variable blocks after watching a Youtube video thinking it might be better than sending each textbox data individually. Probably watched the wrong video LOL

The first block is a leftover from many things I tried to achieve the renumbering, should have taken it out before I created the image, sorry

What I want to do (thinking ahead) is to allocate EEPROM address blocks on the Arduino using the ID number. No idea if this is the right way to go about it but it's the only way I can think of at the moment.

If I enter a room name for instance for "name_TxtBox", this will be used as the "tag". The ID_TxtBox will be 1 and whatever else I enter in the other 4 textboxes. All of the contents of the 6 boxes is actually the "tag".

In the "Spinner" view I see:
Living Room,1,12,13,14,15
Kitchen,2,11,12,13,14,
etc

I then send everthing in the list to the Arduino.
In the Arduino Sketch I then sort out the list and allocate EEPROM address block for each "tag".

ie:
If ID = 1 then EEPROM address block is from 1 to 6
If ID = 2 the EEPROM address block is 7 to 12
etc etc

However, if I delete 1, then the address block allocated for this ID will not be used again; hence, the need to renumber the IDs starting from one again.

Thank you, I will give this a go

Taifun


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

Thanks for the links, I will look at them both later on