Increase value +1 per loop

Hello, I want to increase the value of the type command by +1 every loop. How can I do that?


(For example, it starts from the first 1 and will increase +1 every loop.)

1 Like

To increase loop or others variable you can use this command

{
  "Command": "executeScript_Sandbox",
  "Target": "return Number (${Loop_Counter}) + 1",
  "Value": "Loop_Counter"
},

Thanks for your answer. I did what you said but I get this error. I’m a newbie, sorry. :slight_smile:
[error] variable “LOOP_COUNTER” is not defined

Your code macro is wrong you must study ui vision docs

https://ui.vision/rpa/docs

Here a code to do a loop, your macro code is wrong.

Macro Code:

{
  "Name": "Loop_Some_Times",
  "CreationDate": "2020-6-12",
  "Commands": [
    {
      "Command": "store",
      "Target": "true",
      "Value": "!errorignore"
    },
    {
      "Command": "bringBrowserToForeground",
      "Target": "",
      "Value": ""
    },
    {
      "Command": "store",
      "Target": "0",
      "Value": "Loop_Counter"
    },
    {
      "Command": "label",
      "Target": "Engine_Code",
      "Value": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "return Number (${Loop_Counter}) + 1",
      "Value": "Loop_Counter"
    },
    {
      "Command": "echo",
      "Target": "Loop Counter Is ${Loop_Counter}",
      "Value": "#shownotification"
    },
    {
      "Command": "gotoIf_v2",
      "Target": "${Loop_Counter} < 5",
      "Value": "Engine_Code"
    }
  ]
}

If you want to type 1, on clicking name sayfa, then 2,3… on consecutive loops.

After command :open, site.com add following:

{
“Command”: “executeScript_Sandbox”,
“Target”: “return Number (${!loop})+1”,
“Value”: “AAA”
},

{
  "Command": "click",
  "Target": "name=sayfa",
  "Value": ""
},

{
  "Command": "type",
  "Target": "name=sayfa",
  "Value": "${AAA}"
},

This code generates the error Loop_Counter is not defined for me. The loop never finishes. End of log:

  • [info]

Executing: | gotoIf_v2 | ${Loop_Counter} < 5 | Engine_Code |

  • [info]

Executing: | label | Engine_Code | |

  • [info]

Executing: | executeScript_Sandbox | return Number ({Loop_Counter}) + 1 | Loop_Counter |

  • [error][ignored]

Line 5: Error in executeScript_Sandbox code: Loop_Counter is not defined

  • [info]

Executing: | echo | Loop Counter Is {Loop_Counter} | #shownotification |

  • [echo]

Loop Counter Is {Loop_Counter}

  • [info]

Executing: | gotoIf_v2 | ${Loop_Counter} < 5 | Engine_Code |

  • [info]

Executing: | label | Engine_Code | |

  • [info]

Executing: | executeScript_Sandbox | return Number ({Loop_Counter}) + 1 | Loop_Counter |

  • [error][ignored]

Line 5: Error in executeScript_Sandbox code: Loop_Counter is not defined

  • [info]

Executing: | echo | Loop Counter Is {Loop_Counter} | #shownotification |

  • [echo]

Loop Counter Is {Loop_Counter}

  • [info]

Macro was stopped manually (Runtime 24.31s)

The code you use is depreated, now it’s possible to create short and more fast code macro

This is my Easy Loop few lines for super speed

Macro Code

{
  "Name": "Easy_Loop",
  "CreationDate": "2020-12-11",
  "Commands": [
    {
      "Command": "times",
      "Target": "10",
      "Value": ""
    },
    {
      "Command": "comment",
      "Target": "After This Line Add Your Command",
      "Value": "#shownotification"
    },
    {
      "Command": "echo",
      "Target": "Loop Number ${!TIMES}",
      "Value": "#shownotification"
    },
    {
      "Command": "end",
      "Target": "",
      "Value": ""
    }
  ]
}

If it is not known in advance how many times the loop runs, how to modify the code into an If or While statement?

Change value in the times

  {
      "Command": "times",
      "Target": "10",
      "Value": ""
    },

This loop 10 time, change with your prefered value.

This does not make the code into an If or While statement. Generates errors if times is too large and the next element not found, misses some links if times is too small.
But good to know if the standard programming constructs If or While do not work with UI.vision.

The while command has no utility, I automate everything (any site) and I have never used the while command, you can very well perform any work with the times command.

I specialized in making very fast macros, with a few lines of code, they occupy little ram and work very well, you less lines of code uses and more professional is the work.