How to show output array of string as int32

I have a for each with a list of string array variable and item as currentItem.
In the body, I have a multiple assign as follows:

Int32 = strArray.Length
Int32 = Int32 + 1

Message Box: currentItem

This displays the strings as names. I want to display them as integers like 0, 1, 2, 3 on every iteration.

Hi @private_matter

To display the strings as integers (0, 1, 2, 3, etc.) during each iteration of the “For Each” loop in UiPath, you can make use of the loop index. Here’s an updated version of your workflow:

  1. Keep the “For Each” loop with the list of string array variable and the item as currentItem.
  2. Add an integer variable before the “For Each” loop, let’s call it index. Set its initial value to 0.
  3. Inside the loop body, perform the following steps:
  • Assign the value of index to a new integer variable, let’s call it iterationIndex.
  • Increment the value of index by 1.At this point, you should have the current string item in the currentItem variable, and the corresponding iteration index in the iterationIndex variable.
  1. Display the iterationIndex variable using the Message Box activity instead of the currentItem variable. This will show the integers (0, 1, 2, 3, etc.) during each iteration of the loop.

Thanks!!

you can also try this Create a Output variable for each and change the variable datatype to int32

as the output varaible starts from idex=0 and place a message inside for each it will display all the values like 0,1,2,3 until the items in array was completed…
thanks

This is not iterating. It results in showing 0 for every loop.

Hi @private_matter

Can you please verify the scope of the variable IterationIndex? It’s most likely to be the Body. If yes, please change the scope to For Each.

Hope this helps,
Best Regards.

Hey @arjunshenoy
i’ts in the Main Sequence most top.

@private_matter

What is iterationindex? is it the variable assign to the index in for loop?

cheers

@private_matter

Are you specifically looking to design the flow in this structure or your objective is just to get the output 0,1,2,3… on every iteration?

Best Regards.

You don’t display an integer. Everything you display is displayed as a string.

My objective is to iterate through a list of string array names and then query them one by one from the entity database and extract an ID for each that will later need to be concatenated into a single string.

The below is where the iteration of numbers should take place. This should be replaced by a variable.

2023-05-25_201304

I usually use the repeat number of times activity as I’m more used to it in iteration but for now, I need the For Each.

@Anil_G
IterationIndex has no value by default. It’s a int32 type.

@private_matter

As youa re not incrementing or changing the value it is showing or writing zero always…the default value for int type is 0

cheers

@private_matter

Please correct me if I’m wrong. In order to match the LocationName with the LocationArray(IterationIndexNumber), you are trying to increment the number like 0,1,2,3 on each iteration, right?

Since you are already iterating through the LocationArray in For Each, you don’t have to access the element like LocationArray(0) or like that. Just try using CurrentItem.ToString.

Hope this helps,
Best Regards.

Yes you’re right. I know I can do that but I simply want to learn how to iterate using Integers in for each loop.

1 Like

with zero and without zero is not iterating :rofl:

@private_matter

In that case, instead of assigning an Index outside the loop & trying to tweak it inside the loop again, you can follow this simple step.

Go to the For Each property panel, identify the Index property & create a new variable there. That variable will be a zero based index variable will work perfectly in sync with the iteration.

Best Regards.

@private_matter

You are not incrmeneting the index value …

Because in your multiple assign youa re first giving index value as 0 then adidng 1 which make sit 1 always as iterationindex is 0

So ideally your index value is 1 always for every iteration

Cheers

can you show a small example as its not iterating still.

@private_matter

In the message box, instead if IterationIndex, just give Index.ToString. It will give you the desired output.

Best Regards.

it shows as 3 3 twice. I have two strings in the array for demo purposes.