Change a components id number once placed on a page

Ok so I have quite a busy page and one of the multiple components on the page is now out of sequence with the rest (16 * bank of two state switches).
I want to simplify my event code and use a for loop to go through each bank of switches.
With one ID now out of sequence, is there a way to change a component ID without inputting the whole page of components in the correct sequential sequence??

Any suggestions would be appreciated

Hi @Crusty,

The ID corresponds to the order on screen. Topmost components have the highest IDs. You can reorder them by cut&paste or by using the “bring to top/bottom” buttons in the Nextion Editor. However, there is no way to increment/decrement the ID. You’re limited to putting a (group of) components to either end.

Hope this helps!
Max

I thought this might be the case.
At the moment I do not see a mechanism to be able to use a sequence of component names in a for loop.
Which is why I asked if the ID’s could be renumbered in any way.
If any one knows how to use n1.val, n2.val, n3.val, n4.val say in a loop I would much appreciate a push in the right direction. As I can easily reorder a component name to be in sequence??

Nope, no other way than using the b[id] array. Usually you’d define a custom array with pointers to each component but nextion doesn’t allow you to define custom arrays.
So reordering is your only option.

Kind regards,
Max

Thanks for the confirmation. In direct C I would be doing as you say.
Now I have all my 2 state switches working in the required way along with all the other elements I need on the page I have opened a new version of a project.
The new project will make sure the components are installed in a sequential order where needed.

You can still put them in whichever order you need. Just reorder them by sending each component to back or to front as you see fit.

Many thanks for your help, I have been able to make the id values sequential.
I had had mistaken “bring to top” and “bring to bottom” of the ID array, as being some like “bring to front” and “bring to back” as with a drwawing object.
The process needs a lot of thinking about to get every thing ordered the way it should be, buts is possible and works.
Many thanks.

1 Like