Start a new topic

Nextion Display If Statement Error

Hi, I want to change the font color of the text when the ' value - number ' of the text overcomes the value 5.000. I tried these commands:

 " if (b0.txt > "5000") b0.pco="63488" 
else b0.pco="65535"  

and i got these errors : "Error: Invalid command:if (b0.txt > "5000") b0.pco="63488 Error: Invalid command:else b0.pco="65535" ...
What was my mistake? What can I do to run the code correct ? Thanks

if statement requires

 - condition to immediately follow

   - conditions enclosed in parenthesis

 - requires block to start new line

   code blocks must have closures

 - requires final closing block on new line

No spaces

  such a small STM32 will not contain code to do interpretive whitespace

Nextion Instruction Set may contain spacing error

 -  the downloadable if Demo does not have errors

see Section 2.25 of the Nextion Instruction Set

Many other examples throughout forum

 including full blown Nextion Logic tutorials.

1 person likes this

if (b0.txt > "5000") b0.pco="63488"

else b0.pco="65535"

Text based evaluation in condition

    is limited to equal to == and not equal to !=

Nextion Instruction Set 2.25 if statement Remark #2

    therefore (b0.txt > "5000" is invalid.

Numeric values are not encased in double quotes

  - only text based values are enclosed in double quotes

Therefore b0.pco="63488" and b0.pco="65535" are invalid

Space between if and condition is not allowed

   therefore if (b0.txt > "5000") becomes invalid

Spaces within condition are not allowed

   therefore (b0.txt > "5000") becomes invalid

Code block needs to be surrounded by braces { }

therefore b0.pco="63488" and b0.pco="65535" are invalid

Code block open must start a new line by itself

Code block close must start a new line **

Final code block closure must start a new line by itself

** when using else or  else if, these are on same line as prev block closure. 

Error: Invalid command:if (b0.txt > "5000") b0.pco="63488

if is not what interpreter is looking for if( is

Error: Invalid command:else b0.pco="65535"

else is not what the interpreter is looking for }else is

Nextion Instruction Set 2.25 if statement Example 1 corrected 

  page 1

 Nextion Instruction Set 2.25 if statement Example 2 corrected

}else if(b0.txt=="2")


 Nextion Instruction Set 2.25 if statement Example 3 corrected



 Your example, requires a conversion to number format to use >

cov b0.txt,sys2,0


2 people like this

Thank you very much for your quick response. 
The text changes correct the color after the parameter of 5000,but I must click on text to change the color. How is possible to change the color automatically without touching the text?

I solve that, thank you very much again

Login or Signup to post a comment