Hi @PeterK thanks for your response, i tried the suggested approach and The Type into activity doesn’t stop at the 2nd StrVal which is the 2nd row of the DT
I think there is a bit of misunderstanding on what the Do While activity actually does.
Do While is a type of loop. It repeats everything in the “Do” section as long as the condition in the “While” Section is true.
It seems like you want to use an “If” activity instead. This activity performs specific actions based on whether the “if” portion of the activity is true or false. So I’m guessing you should replace the Do While activity with an if Activity. In the condition, put row_Count <= 2. On the true side, but your message box activity. Leave the false side blank.
Now that I can see your whole for each row activity, the reason why it isn’t working is because row_Count is never changing value.
You are counting the total number of rows in datatable DT. The number of rows is the same every time, so if it is true once it is always true. If it is false once it is always false. Do you want it to only show the message box if the current row it’s working on is <= 2? If so, remove row_count variable all together. In your if activity change the condition so it is: DT.Rows.IndexOf(row) <= 2
it works! will this yield the same results in a Do While? I’m assuming to go through the whole row i’ll have to use DT.Rows.IndexOf(row) < > DT.Rows.IndexOf(row)
No I think there is still a misunderstanding of what the Do While loop is performing. Do While is a loop structure that will perform everything within the “Do” section forever until the “While” condition is not true. I don’t think you’d want to use a Do While here at all.
What the solution is currently doing is going through each DataRow (variable called ‘row’ in your workflow) in your DataTable (variable called ‘DT’ in your workflow). It is then checking the index of the current datarow within the datatable. One important note is that the datatable starts at an index of 0, so if you want only the first 2 rows in the datatable, then your if condition should be <= 1
If by “go through the whole row” you mean each column within the row, then you should just add more assign activities. So create a string variable and assign it like this: YourStringVariable = row.item("YourColumnName").ToString
You would want to continue using the For Each Row activity instead of the Do While activity. That ensures it goes through each row in the datatable and ends the loop once it is done with the last row.
If you really want to use a Do While (or While) loop, then you certainly can. You just need to create a separate integer variable to keep track of the row index, then increment that index by 1 every loop - i’ll call this integer variable counter.
Assign Counter = 0
All of the below is contained in a the DO section of a Do While activity:
In the Condition section of the Do While activity, put the following:
DT.Rows.IndexOf(Dt.Rows(0)) <= 2
It is better to just use a break activity in your for each row loop if you only want to loop through until the condition is reached, as using the Do While loop is a bit more complicated.