Start a new topic

if statement

is it possible to compare values of two variables? 



if(va0.val>va1.val)

{

do something

}


if not possible is there any way to do 


Not sure of your question

what happened when you used the code above?

- did you get an error?

- what was the error code returned?

when I used above code it gives following error


Error: Invalid Variables:va3.val( Double click to jump to code)


when I compare same variable(va3) with number say 100 , code compiles without error


if(va3.val>va0.val) gives error

if(va3.val>100) compiles without error

I would re-examine your code, perhaps even retype to ensure you do no use O instead of 0.  The format you presented is valid if variables va0 and va1 exist and the > condition is true.  Be careful to ensure you do not add spacing.

if(va0.val>va1.val)

{

  printh 65

}



I can implement the same logic by calling the values of variables in MCU(arduino).

But it would be better if the code is inside nextion display coding. 

examine the if statement format in Nextion Instruction Set

be cautious as there is no space between if and parenthesis

and there is no space between brace and else


Your formatting you used at beginning is correct


if(va0.val>va1.val)

{

  printh 65

}


why you get a compile error is because you made a mistake

well , yes it is my mistake

I am comparing two variables from different pages

I should have used system variables sys0, sys1 etc.as per documentation 

after using system variables my problem got solved.

still I have few questions

1) when the scope of the variable is global why can't they be accessed across pages?

2)if they are so, then what is the difference between local and global? 

many thanks for your quick replies

thanks again


variablenames accross pages are not mandantory unique ...


therefore, to access globals of other pages than current, you must use a page prefix ....


pagename.varname.val


...

thanks Gerry. I must have overlooked prefix thing in the documentation

thanks again everybody

 

Login or Signup to post a comment