"Times" command does not reset the ${!Times} Variable

Hi,

When I run the “times” command loop, the internal variable ${!Times} does not reset.
With other words if I run a macro with a “times” command to loop 3 times the
${!Times} variable gets assigned 1,2,3

When I run the same macro without closing the console a second time to loop 3 times
${!Times} variable gets assigned 4,5,6

That is not helpful when I use the ${!Times} variable as an index of something in the loop

also there is an error in the documentation:
https://ui.vision/rpa/docs/selenium-ide/times
→ echo This is loop number {!times} → ( dollar sign is missing in front)

Thanks a lot.

1 Like

Hi, do you have a test macro for us?

I tested with this macro and everything works fine, even with nested loops:

{
  "Name": "nested times loop",
  "CreationDate": "2020-4-22",
  "Commands": [
    {
      "Command": "times",
      "Target": "5",
      "Value": ""
    },
    {
      "Command": "echo",
      "Target": "outer loop=${!times}",
      "Value": "blue"
    },
    {
      "Command": "times",
      "Target": "5",
      "Value": ""
    },
    {
      "Command": "echo",
      "Target": "middle loop=${!times}",
      "Value": "pink"
    },
    {
      "Command": "times",
      "Target": "5",
      "Value": ""
    },
    {
      "Command": "echo",
      "Target": "inner loop=${!times}",
      "Value": "green"
    },
    {
      "Command": "end",
      "Target": "",
      "Value": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": ""
    }
  ]
}

I fixed it now. Thanks!

Actually I just found out the variable “!time” does not reset if you run the script, stop it before it ended and then run it again or if you interrupt the loop any other way before it ends.

The first script will not reset the “!time” variable when you run it over and over.
The second script you can stop it before it finished and run it again to see the effect

{
  "Name": "Test 2",
  "CreationDate": "2020-4-22",
  "Commands": [
    {
      "Command": "times",
      "Target": "50",
      "Value": ""
    },
    {
      "Command": "echo",
      "Target": "${!times}",
      "Value": ""
    },
    {
      "Command": "gotoLabel",
      "Target": "exit",
      "Value": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": ""
    },
    {
      "Command": "label",
      "Target": "exit",
      "Value": ""
    }
  ]
}

Second:

{
  "Name": "Test 2",
  "CreationDate": "2020-4-22",
  "Commands": [
    {
      "Command": "times",
      "Target": "50",
      "Value": ""
    },
    {
      "Command": "echo",
      "Target": "${!times}",
      "Value": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": ""
    }
  ]
}

Issue confirmed, thanks for reporting it!

I think I have seen the same bahavior for the “foreach” loop where i have loaded a csv into an array. When I interrupted the loop it would continue at the same position of the array where it stopped before.

Yes, good catch! The same issue was with forEach. We fixed that already internally along with the times issue :slight_smile: It will be in the next update!

ForEach Test macro:

{
  "Name": "DemoCsvReadArray",
  "CreationDate": "2020-4-24",
  "Commands": [
    {
      "Command": "store",
      "Target": "fast",
      "Value": "!replayspeed"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var arr = []; for(var y = 0; y < 100; y++){arr[y] = y}; return arr",
      "Value": "array1"
    },
    {
      "Command": "forEach",
      "Target": "array1",
      "Value": "elem"
    },
    {
      "Command": "echo",
      "Target": "Element=${elem}",
      "Value": "blue"
    },
    {
      "Command": "end",
      "Target": "",
      "Value": ""
    }
  ]
}

I just want to let you know, that you guys are GREAT !!! I very much appreciate the quick responding. :slight_smile:

1 Like

Fixed with V5.6.5 :slight_smile:

1 Like

Pulling the echos behind an inner loop will let this run all stray!

 {
   "Name": "test_times2",
   "CreationDate": "2020-12-3",
   "Commands": [
     {
       "Command": "times",
       "Target": "2",
       "Value": ""
     },
     {
       "Command": "times",
       "Target": "2",
       "Value": ""
     },
     {
       "Command": "times",
       "Target": "2",
       "Value": ""
     },
     {
       "Command": "echo",
       "Target": "inner loop=${!times}",
       "Value": "green"
     },
     {
       "Command": "end",
       "Target": "",
       "Value": ""
     },
     {
       "Command": "echo",
       "Target": "middle loop=${!times}",
       "Value": "pink"
     },
     {
       "Command": "end",
       "Target": "",
       "Value": ""
     },
     {
       "Command": "echo",
       "Target": "outer loop=${!times}",
       "Value": "blue"
     },
     {
       "Command": "end",
       "Target": "",
       "Value": ""
     }
   ]
 }

To reset the counter you can simple use your custom counter with gotoif and you can do not use times command and have the same command.

@jamacoe Thanks for the example. Indeed, $times is not clearly defined in nested loops. I created a ticket for it.

The workaround is as @newuserkantu suggested: Use a custom counter variable

1 Like

Fixed in V6.0.2: ${!times} now shows the index value of the loop it is currently in (= it will have a different value in the inner, middle or outer loop.

2 Likes