I have a form with 5 labels (Label1,Label2,Label3,Label4,Label5)
I want to be able to set the .text of each label within a loop and also how many labels to write to.
I found an example but it doesn't write the text to the label.
B4X:
Process Globals
Private Label1 As Label
Private Label2 As Label
Private Label3 As Label
Private Label4 As Label
Private Label5 As Label
Private lbls() As Label
End Sub
'
Sub AppStart (Form1 As Form, Args() As String)
'
lbls = Array As Label (Label1,Label2,Label3,Label4,Label5)
'
For i = 0 To lbls.Length -1
lbls(i).Initialize("lbls")
lbls(i).Tag = i + 1
lbls(i).text = i + 1
Next
'
You should load them into a layout first...
Or add the buttons to the form programatically.
Note that
- if you load a layout you should not use INITIALZE
- If you dont use a layout then you need to add the labels manually to the Activity(form)
Sub Process_Globals
Private lbl1 As Label
Private lbl2 As Label
Private lbl3 As Label
Private lbl4 As Label
Private lbl5 As Label
Private lbls() As Label
End Sub
'
Sub AppStart (Form1 As Form, Args() As String)
'
MainForm = Form1
MainForm.RootPane.LoadLayout("lytMain") 'Load the layout file.
'
lbls = Array As Label(lbl1,lbl2,lbl3,lbl4,lbl5)
'
For i = 0 To lbls.Length -1
lbls(i).Initialize("lbls")
lbls(i).Tag = i + 1
lbls(i).text = i + 1
lbls(i).TextSize = 11
Next
When I run this each label shows "Text" instead off "1", "2" etc