Probably a simple thing but it is screwing with my head.
At times in a project I have a number of labels [lblF0 -- lblF15] that need their text colour changed. The text on the label is assigned by the user so this cannot be used to identify the label.
I can do this by changing each label individually I am trying to do it within a loop but trying to identify the label by name triggers errors. I've tried several variations and usually get a Mixed Type error.
For Each v As View In Activity.GetAllViewsRecursive
If v Is Label Then
Private LblFF As Label = v
For W = 0 To 15
If v = "lblF"&W Then 'It is here trying to Name the Label from the loop is where I fail.
LblFF.TextColor = Colors.Gray 'If I can get the principle correct the colour can be varied.
End If
Next
End If
Next
Thanks in advance for the simple answer that will be obvious once you tell me.
Or you could store the target labels in an array an access them directly:
B4X:
Dim TargetLabels() As Label = Array As Label(Label1,Label2,Label3,Label4,Label5,Label6,Label7,Label8,Label9,Label10,Label11,Label12,Label13,Label14,Label15)
Then:
B4X:
Sub Button1_Click
For i = 0 To TargetLabels.Length - 1
TargetLabels(i).TextColor = Colors.Red
Next
End Sub
Sub Button2_Click
For i = 0 To TargetLabels.Length - 1
TargetLabels(i).TextColor = Colors.Gray
Next
End Sub
Or you could store the target labels in an array an access them directly:
B4X:
Dim TargetLabels() As Label = Array As Label(Label1,Label2,Label3,Label4,Label5,Label6,Label7,Label8,Label9,Label10,Label11,Label12,Label13,Label14,Label15)
Then:
B4X:
Sub Button1_Click
For i = 0 To TargetLabels.Length - 1
TargetLabels(i).TextColor = Colors.Red
Next
End Sub
Sub Button2_Click
For i = 0 To TargetLabels.Length - 1
TargetLabels(i).TextColor = Colors.Gray
Next
End Sub