Support Portal

for ProcessRobot and WinAutomation

Start a new topic
Answered

How to get number of times a loop ran?

My process has a 'For Each Loop' action. Sometimes when the process fails or show error for some reason I want to know how many times the loop ran. Is there any way to know that?

waj

Best Answer

Having an issue with my machine currently, so I can not view your waj, today.


However, in answer your question in the meantime, you can do in 2 different ways.


1)   If you put the Begin End - Exception Block in the Main Tab of designer and enclose your entire main processing within the block, it will act as a General Error Handler for an error that is raised within the main process and all functions the main process calls and all nested function called from within those functions, as well,


2)  You can also have the Begin Exception Block in the Main process and another Begin Exception Block in a Function too.  The most Begin Exception Block that covers the Function then would take precedence for the actions coded within it.  In this Begin block in the function, in its option to run another function upon exception error like the "error function", i described above, after your Display Msgbox action you will want to follow it with a Stop Process action, so that you do not return to the main process and continue executing upon capturing the error, as you want the process to stop.


... Note:  Run the process, in designer, 1 next action at a time (F9 Key), and you will be able to view how the begin end exception block handles the unexpected error.  Test by placing a action in the loop that will fail.

 I created the counter variable but it shows loop ran value+1.


.... make sure only for artithmetic to have the right % after the " +1" (and not after the variable name, as below )...


Set %Count%  = %Count + 1%



add a counter variable ... as below


------
main process

-------


Begin Exception Block  ( Choose Run Function option - (e,g, "Function Error ")


Set %Count%  =  0
For Each

Set %Count%  = %Count + 1%        ....(or you an use the Increase Var, action)
....
....
End Loop

End Exception Block


====================

Function

====================


Function "Error"

Display MsgBox - with Message Field:  Unexpected Loop Error and Count = %Count%

Thanks for your reply. I have a question. My loop has 3 actions. Should I add the exception block option for all 3 or is there an exception handling option for the main function? I created the counter variable but it shows loop ran value+1. Please have a look at below attached process.

waj
Answer

Having an issue with my machine currently, so I can not view your waj, today.


However, in answer your question in the meantime, you can do in 2 different ways.


1)   If you put the Begin End - Exception Block in the Main Tab of designer and enclose your entire main processing within the block, it will act as a General Error Handler for an error that is raised within the main process and all functions the main process calls and all nested function called from within those functions, as well,


2)  You can also have the Begin Exception Block in the Main process and another Begin Exception Block in a Function too.  The most Begin Exception Block that covers the Function then would take precedence for the actions coded within it.  In this Begin block in the function, in its option to run another function upon exception error like the "error function", i described above, after your Display Msgbox action you will want to follow it with a Stop Process action, so that you do not return to the main process and continue executing upon capturing the error, as you want the process to stop.


... Note:  Run the process, in designer, 1 next action at a time (F9 Key), and you will be able to view how the begin end exception block handles the unexpected error.  Test by placing a action in the loop that will fail.

 I created the counter variable but it shows loop ran value+1.


.... make sure only for artithmetic to have the right % after the " +1" (and not after the variable name, as below )...


Set %Count%  = %Count + 1%



1 person likes this
Thank you. Running successfully.
Login or Signup to post a comment