label.text question
I want the user to be able able to click on one of many labels and call the "subA" method and the backcolor changes for just that label. I am just learning to reuse code and thought this might be good practice. This is what I tried but no luck. Thanks for help
-------------------------------------------------------------------------------------------
Private Sub LblA_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LblA.MouseClick
Label1.Text = "LblA"
Call subA()
End Sub
Public Sub subA()
Dim a As String
a = Label1.Text
If a.BackColor = Color.Gainsboro Then
a.BackColor = Color.PaleGreen
Else : a.BackColor = Color.Gainsboro
End If
End Sub

label.text question
incendy
johnseab
Gmorken
RayClark096
Try something like this
subA(label1)
public Sub subA(byval a as label)
if a.backcolor.equals(color.gainsboro) then
a.backcolor=color.palegreen
else
a.backcolor=color.gainsboro
end if
end sub
Muhammad Adel
try this, you were trying to use a string and thinking it was a label which is incorrect. This should be done like this:
Private Sub LblA_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LblA.MouseClick
Me.Label1.Text = "LblA"
Me.subA(Me.Label1)
End Sub
Public Sub subA(ByVal theLabel as Label)
Dim a As String
a = theLabel.Text
If theLabel.BackColor = Color.Gainsboro Then
theLabel.BackColor = Color.PaleGreen
Else
theLabel.BackColor = Color.Gainsboro
End If
End Sub
does this help
bennymacca
NickNotYet
a string does not have color attributes or properties...try this:
Private Sub LblA_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LblA.MouseClick
Label1.Text = "LblA"
subA(Label1)
End Sub
Public Sub subA(byval TheLabel as Label)
If TheLabel.BackColor = Color.Gainsboro Then
TheLabel.BackColor = Color.PaleGreen
Else
TheLabel.BackColor = Color.Gainsboro
End If
End Sub
edit: Sorry ken...got busy while tring to post!