Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27379

The Controls Went in One by One, But Backwards!!!

$
0
0
Hi,

I have a form with many labels, I want to be able to access some of them like in older versions with a control array. My code is:

Public structure myInfo
Public Position as label
End structure

Public myData(165) as myInfo

This holds the 165 labels that I want. I have a sub with the following code that puts the labels in, see next.

Dim myCtrl as Control
Dim intCount as int16


For each myCtrl in Me.Controls
If TypeOf myCtrl Is Label AND myCtrl.Name.Contains("lblPositionalDATA") Then

IntCount = intCount. + 1
MyData(intCount).Position. = myCtrl

EndIf
Next

The labels I want are Named. lblPositionalDATA001 upto lblPositionalDATA165. The code worked, but on checking I found the label controls were loaded in backwards eg myData(1).Position = lblPositionsDATA165. How do I get the labels in, in the correct order? I've noticed the tab order of the controls are sequentially correct, I've tried moving them around on the form, I can get what I want by setting intCount = 165 and then decrementing the count, but I'm sure there is another way.

Cheers for any suggestions, ToastyJones

Viewing all articles
Browse latest Browse all 27379

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>