I want to handle an Computer vision automation where loop count is not fixed. For some case the count is 3 for some count is 7 likewise. So, what condition need to apply in while loop to handle this type of situation? Please refer to attached screenshot.
Hi @Neha_Aggarwal1
Below is a sample workflow with while loop you may refer for.
# Get the OCR text from the image
ocrText = GetOCRText(image)
# Get the number of iterations required
numIterations = ocrText.Length
# Initialize a counter
counter = 0
# Use a while loop
While counter < numIterations
# Perform your automation logic here
# Increment the counter
counter = counter + 1
End While
Hi,
I can see in the first column there is a value. you can do one thing in the while loop’s body that, if column_value = “” that means blank or null then break.
Basically we have the same option as the normal activities, you can use the CV Extract Table Activity, it will returns the entire datatable, then you can just use the dt.RowCount to return the max iterations or just loop through the datatable
As u see in the image, I have to first click on First blue line then capture the yellow area by cv get text likewise I need to come in second line and capture the text in the box.
this steps i did perfectly but the main difficulty I am facing is now here there are 3-line description for some case there are 5 or 7 lines so how to handle that in loop what condition need to apply.
bool moreLines = true
while (moreLines)
{
// Capture the text of the current line using the "CV Get Text" activity
// Check if there is a next line
// If there is a next line, continue the loop
// If there is no next line, set moreLines to false to exit the loop
}
In this example, the loop continues as long as the moreLines variable is set to true . Each iteration of the loop captures the text of the next line, and checks if there is a subsequent line. If there is no next line, the value of moreLines is set to false to exit the loop.
Why is there a need of counter <=2? as you are checking it dynamically it only should be true and once internal condition is false then break it on the basis of if the value is null then use break activity.
string currentLine = readLine();
if (currentLine == null)
{
// There is no next line
}
else
{
// There is a next line
}
To check if there is a next line, you can use a method that returns a Boolean indicating if there is a next line or not. The exact method would depend on the language and environment you are using, but a common method in many programming languages is to use the readLine() method which returns a string of the next line, or null if there is no next line. You can then check if the result is null to determine if there is a next line.