Dynamically use control names


I would just like to find out if it is possible to do the following.

So, I have a range of “ProgressBars” which displays the cpu cores output, so I need a way to update a certain amount of “ProgressBars” depending on the core count.

     //Previously generated values gives me the core usage values (cpuUsage variable) in the order of eg. 43&12&65&78 So i use split to get them in an array.
      Dim CpuValues(-1) As String
      CpuValues = Split(cpuUsage,"&")

      Dim CounterA As Integer=1    // I start by using the number "1" because that is where the first core's value is stored in the array.
      Do Until CounterA = CpuValues.Ubound
            vcbar1.Value = Val(CpuValues(CounterA))
            CounterA = CounterA + 1

So, as you can see i am only updating vcbar1 because i am unsure how i would dynamically add vcbar2,vcbar3 and vcbar4 in the DoUntil loop without refering to specific names, what it comes down to is i need something like the following

      vcbar(CounterA).Value = Val(CpuValues(CounterA))

Please if anyone would kindly assist me by either give me a better solution or an answer to the current issue.
Thanks in advance,

  • Dian Opperman

You would probably find it a lot easier to do the update depending on the index with all the progressBars in a control set.

It’s definitely best to approach this the way that @Michel Bujardet suggested.

In order to create a control set, you just need to start by naming one progress bar whatever name you choose (vcbar).
Then when you name the next progress bar with the exact same name, the IDE will ask if you want to create a control set, choose OK.
You can repeat that process for as many controls as you want in the set.
Then you can address them as vcbar(0), vcbar(1), vcbar(2), etc. So in your case you would use vcbar(counterA - 1) since you are starting your loop at index 1 and the control set starts at index 0.


Select the control, then click this icon in the inspector:

Sorry for the late reply, thank you so much! That answers all my questions.