I'm just starting to dabble in VB (using Express v8), and would like to have a list of Labels showing the open/close status of each door in my house (DoorState1, DoorState2, DoorState3, etc.). Is there a way to reference a Form Control object (in this case, a Label) using a string variable instead of explicitly naming it? I'm not clear on the terminology I want to use here -- reference, dereference, pointer, etc. come to mind from my programming days -- but that was 20+ years ago!
What I'm looking to do is replace code that looks like this:
Select Case DoorNum
Case 0
DoorState0.Text = "OPEN"
DoorState0.ForeColor = Drawing.Color.Green
Case 1
DoorState1.Text = "OPEN"
DoorState1.ForeColor = Drawing.Color.Green
Case 2
DoorState2.Text = "OPEN"
DoorState2.ForeColor = Drawing.Color.Green
Case 3
DoorState3.Text = "OPEN"
DoorState3.ForeColor = Drawing.Color.Green
...with something cleaner that can append the DoorNum to the end of a fixed string and use the resulting string variable as the name of the Label I want to update. How do I get a pointer to an object in the current Form f I know the name (and class) of the object??
Dim testField As String
Dim testObj As System.Windows.Forms.Label
testField = "DoorState" & DoorNum
testObj = ' get the Label named testField in the current Form
testObj.Text = "OPEN"
testObj.ForeColor = Drawing.Color.Green
I hope that makes sense... Any thoughts?
Thanks in advance...
jim