Start a new topic
Implemented

if condition with "else" option

It would be very interesting to have the "else" clause in the "if"clause, like any programming language. Please, see the simple example:

if (t0.txt == "1")

{

    t1.txt = "Number 1"

}

else

if (t0.txt == "2")

{

    t1.txt = "Number 2"

}

else

{

    t1.txt = "Number not 1 and 2"

}

Thank you


1 person likes this idea

That is already planed for V0.33, see : http://support.iteadstudio.com/support/discussions/topics/11000000361

Honestly, I am no big friend of special commands without a real need, especially in case you can just use existing ones an ease to archive the same goal ... This only bloats things and waste ressources ...

if(t0.txt == "1")
{
t1.txt = "Number 1"
}
if(t0.txt == "2")
{
t1.txt = "Number 2"
}
if(t0.txt != "1")
{
if(t0.txt != "2")
{
t1.txt = "Number not 1 and 2"
}
}

 

But that's only my opinion ... :-)


G.

Gerhard!
The solution is not working. Nested branches can not run.


A workable solution:       (default : va0.val=3)

if(t0.txt=="1")
{
va0.val=1
}
if(t0.txt=="2")
{
va0.val=2
}
if(va0.val==1)
{
t0.txt="Number 1"
}
if(va0.val==2)
{
t0.txt="Number 2"
}
if(va0.val==3)
{
t0.txt="Number not 1 and 2"
}
va0.val=3



Why shell it not work?
Where can you read, that it is forbidden to use nested IF conditions?
Normally, the typo of an if construct is very picky, one space too much and it is not recogniced or produce an error ...
But in general, when using the correct syntax, it works very well ...

Regards  Gerhard

 

JPG
(33.7 KB)
HMI
(6.59 KB)

1 person likes this
The syntax is correct, but it gave me an error message. The attached picture shows previously seen.
But what you are now attached at work.

 

:-)

 

Try to implement it in Nextion editor, as simple as, for example php, C, javascript and so on.
Example:
if(t0.txt==":")
{
t0.txt=" "
}
else
{
t0.txt=":"
}
What is it???
http://wiki.iteadstudio.com/Nextion_Instruction_Set#Conditional_Statements_In_Nextion:_if

************************************

Instance 2: Below codes can switch content of txt of button component b0 between start and stop in press event)

if(b0.txt==”start”
{    
  b0.txt==”stop”  
} else
{ 
  b0.txt==”start”  
}
Instance 3: Below codes can switch content of txt of button component b0 among 1, 2, 3 in press event)
if(b0.txt==”1”
{    
  b0.txt==”2”  
} else if (b0.txt==”2” )
{ 
  b0.txt==”3”  
}else
{ 
  b0.txt==”1”
}

**********************************

 


1 person likes this

V033 supports "else"


2 people like this
V033 It will contain multi comparison?
Example:
if(va0.val==1 && va1.val==1)
{
va2.val=2
}

///////////////////////////////////////

if(va0.val==1 || va1.val==1)

{

va2.val=2

}

http://wiki.iteadstudio.com/Nextion_Instruction_Set#Conditional_Statements_In_Nextion:_if

if(b0.txt==”start”
{    
  b0.txt==”stop”  
} else
{ 
  b0.txt==”start”  
}

Is it correct to write 
if(b0.txt==”start” 
instead of 
if(b0.txt==”start”)
Is it correct to write 
b0.txt==”stop” 
instead of  
b0.txt=”stop”

 The article is written incorrectly
there is an error.

Right like that:

if(b0.txt==”start”)
{    
  b0.txt=”stop”  
} else
{ 
  b0.txt=”start”
}
"==" - comparison operator
 "=" - assignment operator

I am now reviewing all of the Feature Requests, this will take some time, patience please.

Timeline needed to be taken into account - implemented


Login or Signup to post a comment