Unofficial Nextion/TJC User Forum

Error when creating a global variable


I am trying to design an algorithm that goes to the previous page with the help of a global variable. However, when I tried to define a variable (let’s say an int i) I get the following error:

Error:Global variable definitions must precede all code in the program.c:int i;( Double click to jump to code)

I do not understand what’s the error here. Is it about the place of the variable? Then where should I define it. I am using Basic NX4832T035_011. I would love to have any comments.

Hi and welcome @ulasus23!

Since the error says that the placement is wrong I’d answer your question with yes, it is about the place of the variable. However, it’s not about what section/page/… you put it into, but about where you put it_within_ the Program.s section. You haven’t shown us your Program.s file so we can only make guesses about what it looks like. I suggest you put all your global variables at the top and everything else (assignments, if/else, loops, print commands, other commands, …) below. Following the error message that seems to be what the editor expects and requires.

Kind regards,

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