Late Bound Resolutions

ALX

Well-known member
Joined
Nov 16, 2005
Messages
253
Location
Columbia, SC
Programming Experience
10+
In the process of trying to get "Option Strict" turned on, I've cleaned up all of the Implicit Conversions in my code, and there were many! Now I'm trying to clear up "Late Bound Resolutions". In a couple of forms, I create almost all of the labels on the form at run time and store them in an ArrayList so that I can get a reference to each label as I need to. When refering to a label in that ArrayList, such as
VB.NET:
Dim n As String = "whatever"

For j = 0 To MyArrayList.Count
    If MyArrayList(j).name.ToString = n Then   '<<< This reference is late bound...
        '(...)
    End If
Next

I have a late bound resolution warning/error. Of course I have the same issue when the form is closing and I have to go through the ArrayList to dispose of all of these labels. This method of creating the labels at runtime is very flexible and convenient, and I hate to lose that by changing my method completely. How can I use this method without creating all of these late bound references to the labels in MyArrayList?
 
Why use arraylist when you have Controls collection? You can even get the control by name with the string indexer.
VB.NET:
Dim c As Control = Controls("mylabel")
If you for reason needed to keep a special collection of these labels you would use a List(Of T), where T is the type, for instance Label or Control.
 
Of course !!! What was I thinking ? !!! This was one of the first sections of my app that was written many months ago, and I was much greener then. Thanks for bringing me to my senses, John.
 
Back
Top