Pass control name in a variable

dorko72
12-29-2003, 04:45 PM
Hello all,
I have a series or label controls i manully created in my form. I have a routine which needs to change the backcolor of a given label. The routine receives the control name as a variable. How can i make it so the routine understand the variable name is actually the label control?


Public Sub UpdateMap(ByVal intstatusCode As Integer, ByVal strStationName As String)
Debug.WriteLine(strStationName) 'this is the label control name
Me."strStationName".BackColor = Color.Aquamarine

End Sub



Thanks!

reboot
12-29-2003, 04:54 PM
Why not pass it the label object itself instead of a string.

dorko72
12-29-2003, 05:18 PM
Thanks for the prompt reply. Can you explain how to do that? thanks!

dorko72
12-29-2003, 05:36 PM
Actually... passing the object would not work... here is my problem:

I am looping through a dataset wich contains a row that has the name of each label i want to work with. Inside the loop i called a sub that needs to change the look of the given label's backcolor so in affect i have the label name, not the object itself.

Thank you!

Csharp
12-30-2003, 03:40 AM
i'd do something like this ...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
UpdateMap(Label1.Name, Color.Aquamarine) '/// you can put a string where it says label1.name ( eg : "Label1" )
End Sub

Public Sub UpdateMap(ByVal strStationName As String, ByVal c As Color)
Dim ctl As Control
For Each ctl In Controls
If ctl.GetType Is GetType(Label) Then
If ctl.Name Is strStationName Then
ctl.BackColor = c
End If
End If
Next
End Sub

Optikal
12-30-2003, 07:50 AM
I would change your application design so that your not storing control names in the database. This is a poor design, and I am sure there is a better way to do whatever it is you are trying to do. If you explain your ultimate goals I'm sure we can help you come up with a more proper design.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum