Use loop counter as part of a variable name

loop
studio
variable

#1

Hello All,

Within my excel file i have the following columns (example)

Number_of_dir
dir_title_1
dir_name_1
dir_title_2
dir_name_2
dir_title_3
dir_name_3
dir_title_X
dir_name_X

Inside number_of_dir can be 1, 2, 3 but a max of 11. I plan to use that value for a ‘while’ loop. number_of_dir>=dirloop, at the end of the while increment the dirloop by 1 and so on.

I’m thinking that i can use the loop value to tag to the end of the variables so i can use the loop to check all the fields without having to build up the sequence

dir_name_dirloop - which translate to dir_name_1

Is this possible?

Do I need to assign all the variables first

dir_title_1 = row(“dir_title_1”).toString

dirloop

Thanks in advance for any advice :smile:


#2

Inside type into activity make dirloop.tostring


#3

You need not store the data in the variable. You can directly use

row(“dir_title_” + dirloop.ToString).ToString


#4

Since posting this the penny dropped and have done it another way around.

When assigning the title set the loop there.

dir_title = row(“dir_title_”+dirloop.tostring).tostring

:smiley:


#5

This is exactly how I’ve done it!! thanks


#6

what a sync! :laughing:


#7

Its like one mind! haha