laredo512
Regular
Hi,
Got this problem trying to change the BackColor of multiple lables.
Using VB.NET pro 2003
I keep getting a reference not set to an instance of an object error....
I'm sure it's something stupid, but I can't put my finger on it.
Thanks for any help provided!
Got this problem trying to change the BackColor of multiple lables.
Using VB.NET pro 2003
Code:
[size=2][color=#0000ff]Private[/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] chgCol([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] LabelNumber [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Integer[/color][/size][size=2])
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] lblMan [/size][size=2][color=#0000ff]As[/color][/size][size=2] Label[/size]
[size=2]lblMan = FindControl("lblman" & LabelNumber.ToString)[/size]
[size=2][color=#0000ff]If[/color][/size][size=2] lblMan.Text [/size][size=2][color=#0000ff]Is[/color][/size][size=2][color=#0000ff]Nothing[/color][/size][size=2][color=#0000ff]Then[/color][/size]
[size=2]lblMan.BackColor = System.Drawing.SystemColors.Control[/size]
[size=2][color=#0000ff]Else[/color][/size]
[size=2]lblMan.BackColor = System.Drawing.Color.Green[/size]
[size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]If
[/color][/size]
Private Function FindControl(ByVal Controlname As String) As Label
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is Label Then
If ctl.Name.ToUpper = Controlname.ToUpper Then
Return ctl
End If
End If
Next
End Function
I keep getting a reference not set to an instance of an object error....
I'm sure it's something stupid, but I can't put my finger on it.
Thanks for any help provided!