Start a new topic

Limiting its range

hi there

i have a button (b15) and when it is pressed it will copy the number from t0 and then clear t0, but i would like it to only add if the number is between 0 and 100?


something like this?


if(t0.txt<="100") && (t0.txt>="0")

{

b15.txt=t0.txt

t0.txt=t0.txt-4

}


thanks Joe


if(t0.txt<="100")

{

 if(t0.txt>="0")

  {

   b15.txt=t0.txt

   t0.txt=""

   }

}


To test two conditions, you must nest the if statements

t0.txt="" is clearing t0.txt to an empty state

t0.txt=t0.txt-4 removes the last 4 characters

   * the t0.txt-4 could cause issues if length of t0.txt < 4

Wait a minute: "t0.txt=t0.txt-4 removes the last 4 characters" - never saw this before. Are there any other string manipulation tricks hidden in the interpreter? A complement to remove leading characters would be nice to have; then we had all we would need to do substr().

Many keyboard demos gave away t0.txt-1 for backspace

just needed to try with -4 to see result


But for substrings

http://support.iteadstudio.com/support/discussions/topics/11000008397

Hey guys,


Before we can start doing math on the text strings, we first need to covert to the numerical value.


The "cov: variable type conversion" in the instruction set allows for this.


Alternatively we could use the number type container in the HMI design.


As the OP has it now, it's a bit like saying "if(t0.txt<="Cat") && (t0.txt>="Dog")

Good Point.  I was focused on the nesting, and .txt-4, my bad.

hi there 

i tried this:


if(t0.txt<="100")

{

 if(t0.txt>="0")

  {




   }

}


and it compile fine but i can not get it to execute, any ideas?


as indev2 pointed out you should either use a number component


if(n0.val<=100)

{

 if(n0.val>=0)

  {

   }

}


or use cov command to convert text number into numeric number

not super sure if < and > compares work for text in this fashion

if(t0.val<=100)

{

 if(t0.val>=0)

  {


   }

}


Coming back with error invalid variables:t0.val

as indev2 pointed out you should either use a number component

if(n0.val<=100)

{

 if(n0.val>=0)

  {

   }

}


or use cov command to convert text number into numeric number

not super sure if < and > compares work for text in this fashion

right ok i have change to using a number that works fine now but now the adding the number  from n0 to b15 comes back with an error (b15.txt=n0.txt) and the clearing of t0 now has a error (n0.txt=n0.txt-4) i presume i need to change that to something that clears not remove the last 4 digits?


and the key pad that puts the numbers in n0 has an error n0.txt=n0.txt+"1" any ideas?


thanks again  

Man, go read the manual... If you do not know the difference between a numeric and a string (text) variable and what is possible or not to do with either, you should take a step back from starting with a MCU and Nextion and do something basic first. Just my 0.02$

@Joes



By the looks of it, you are still confused on what can be done with .txt and .val attributes.


A keypad that enters .txt (ascii) numbers into a textbox is a simple and viable method on Nextion.


Transferring that text string (it is not a number !), to the .txt attribute of a button is also simple enough.

Standard Buttons do not have a .val attribute !


If you want to do the limiting checks, then you would bring a numerical variable into the equation.


Assign a Nextion variable say va0, make sure it's type is set to number.


Then using the cov command...


cov t0.txt,va0.val,0


if(va0.val>=0)

{

  if(va0.val<=100)

  {

    b15.txt=t0.txt

    t0.txt=""

  }

}

Login or Signup to post a comment