Unofficial Nextion/TJC User Forum

Current Component ID

Hello everyone,

There is the “dp” variable which gives you the ID of the current page. I wondered if there’s something similar for components. Reason: I have a keyboard (didn’t like the “default” keyboard) and each key appends its “.txt” value to a text field. This would be much easier if there’s something like “self.txt” or “p[dp].b[currentID].txt”. Because this does not need to be modified for each key. There are many other cases where direct access to the components properties would make life a lot easier.
Am I overlooking something?

Thank you!

Hi Max,
Unless I’ve read your question wrong, this already exists for each component. It’s the second line down on component attributes. I have used it to clear multiple text boxes to null and number boxes to zero with a ‘for’ loop (eg ‘page0.b[x].txt=’ or ‘page0.b[x].val=’). Just ensure you prefix with letter ‘b’
However, you have already indicated this in your question.

So - do you mean putting them into some sort of logical order. If so then this can be a pain if you have a number of them. Select a component then click the up or down arrow (bring top/bring bottom) under the Open icon top left of the editor screen. Do this for each one you want to reference to sort them into a sequence.

Hi Bobj,

Thanks for your reply. Unfortunately that’s not what I meant. I know each component has a unique ID. And I know you can reorder components.

Let me elaborate the given example a little more. I want to create a keyboard to type the characters “A”, “B”, “!” (random selection). The target component is “tTarget”, the buttons are labeled “bA”, “bB”, “bExcl”, whose “.txt” attribute contains the caracter they shall type.
In the touch release event of “bA” I write:
Not too hard, right? But this code line only works for “bA”. For “bB” and “bExcl” I have to modify it. Even worse if you don’t have 3 keys, but dozens. Therefore I hoped there was something like a “self” variable that always points to the current component. So I could write
And it would work for every button.
As I said, this exists for pages. If I want to access the current page, I can do it on any page with the same expression p[dp]. dp automatically contains the ID of the active page. But I couldn’t find a similar variable that always contains the ID of the active component.

I hope this makes my question more clear. Oh, and I have another question: there is no possibility to define a function, right? I needed to calculate a square root, and I implemented it with a hidden number element, that I triggered with a click command. There is no simpler way, right…?

Kind regards,

Hi Max,
Can’t answer this one…
But - re the function problem - this may help
Add a Hotspot and put to back so it can’t be clicked - size doesn’t matter.
Put your function code in the Touch/release event of the Hotspot.
When you want to call the function use ‘click m0,1’ or 0 (and change m0 to yours). You will need to use variables to pass parameters.

Hi Bobj,

Yeah, that’s pretty much what I currently do. It’s okay unless you need the function during preinitialization (before anything appears on the screen). The click command makes Nextion draw everything on the screen even if the clicked component is not visble.

Thank you anyways!

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).