Comparing variables


#1

I have tried every way that I know to check if a variable is within a range. For example if I try

 {
   "Name": "Test",
   "CreationDate": "2018-12-7",
   "Commands": [
 {
   "Command": "store",
   "Target": "1",
   "Value": "one"
 },
 {
   "Command": "store",
   "Target": "5",
   "Value": "five"
 },
 {
   "Command": "store",
   "Target": "10",
   "Value": "ten"
 },
 {
   "Command": "store",
   "Target": "100",
   "Value": "hundred"
 },
 {
   "Command": "storeEval",
   "Target": "${one} <= ${hundred} <= ${ten}",
   "Value": "A"
 },
 {
   "Command": "echo",
   "Target": "${A}",
   "Value": ""
 }
 ]
 }

This comes out true for me, no matter what number I plug into the middle. I have tried it with the “if” command and “storeEval”, using stored variables and the numbers themselves. It always returns the same true/false readout no matter the middle number. I have also tried using “<=” and just “<”.


#2

Kantu’s storeEval and flow control follows exactly the Javascript syntax. So the right way is to use && (and operator):

parseInt ("${a}") > 5 && parseInt ("${a}") < 15

Test macro:

{
  "Name": "compare var",
  "CreationDate": "2018-12-8",
  "Commands": [
    {
      "Command": "store",
      "Target": "10",
      "Value": "a"
    },
    {
      "Command": "if",
      "Target": "parseInt (\"${a}\")  > 5  && parseInt (\"${a}\") < 15",
      "Value": ""
    },
    {
      "Command": "echo",
      "Target": "Var in range!",
      "Value": "green"
    },
    {
      "Command": "else",
      "Target": "",
      "Value": ""
    },
    {
      "Command": "echo",
      "Target": "Var outside range",
      "Value": "red"
    },
    {
      "Command": "endif",
      "Target": "",
      "Value": ""
    }
  ]
}