Unofficial Nextion/TJC User Forum

How to index objects on a page

I have five numeric display boxes on a page, and I want to put values into them without calling them specifically. Can I index them? And if I do index them, do I use their name or the object id?

For example, suppose I have display boxes, n0, n1, n2, n3, n4, n5, and want to populate the five displays like this…


I would assume that the variable “k” would take the place of the object id. But this does not work. I get an invalid variable error. I have tried making them all global. And I have tried putting the page number in there as well (page0.n[k].val, and page[0].n[k].val). Same errors all the way around.

Any help would be appreciated.


Two indexed arrays exist in Nextion firmware for this purpose, the p[] and the b[] array. Each component can thus be addressed by

Thank you. So buttons and pages can be indexed, nothing else can. Well, I could use buttons for the numeric displays.

Thanks again

Let me ask a follow up question. How would I learn this information without asking this forum? Is there a manual available, aside from the instruction set?

You‘re confusing two things. The b[] array gives access to all components on that page. The name of the array is not related to the name of the components, like buttons f.ex. Remember, you can rename your buttons to anything you like. Instead of b0, b1, b2, … they could be called return, enter, ok, blubblub, … And you could still access them over this array just like you can for numbers, dual state buttons and all the other components. There‘s no exception.

The instruction set covers I‘d say 90% of the knowledge. Nextion has some additional blogposts but really most of the stuff you need to know is on the instruction set page. Yes, these arrays are mentioned and explained there, too.

Kind regards,

That is very valuable. Thanks so much.

To avoid this confusion, I had written “each component”, regarding the b[] array. “Each component” was NOT intended to be “buttons only”. Sorry if that hasn’t been clear.

No worries. It’s my mistake. I’m not used to this level of programming. I just saw code that said p[i].b[k].txt=“xxxx”, and I made the assumption that “b” referred to buttons.


I tried the index function with 2 buttons and a textbox. It works fine.
I set b[1].txt=“Test1” (button)
b[12].txt=“Test2” ( button)
b[15].txt=“Test100” (textbox)
It’s convenient. However, you can’t manage the Id (the index) of each object. For that reason, you have to create all your array objects immediatly to be sure to have a continue index in order to realize a for next loop.
Moreover, the b name is not very explicit.

I am right ?

Best regards


In the Editor toolbar, there are options to arrange the object order and with it, the object ids. And no, the b name is not explicit, but most people are already happy and satisfied with that indirect addressing.

From the Nextion Editor guide:

The Component Layout Toolbar
For Renumbering components: Bring Top (Arrow Up) will take the selected component(s) and renumber to the highest .id on the page. Bring Bottom (Arrow Down) will take the selected component(s) and renumber to the lowest .id starting at 1 (page component is always 0) on the page.

This forum is in no way affiliated with NEXTION®, ITEAD STUDIO®, TJC®, or anyone else really. All product names, logos, and brands are property of their respective owners. All company, product, and service names used in this website are for identification purposes only. Use of these names, logos, and brands does not imply endorsement from the respective rights holder(s).