I have 16 labels [lblF0 to lblF15] the text of these labels is changed by the user.
I wish to build a list [Item0 to Item15] showing the text of the labels, first thought was a For/Next loop [ i = 0 to 15].
EG
B4X:
private temp as string
For i = 0 to 15
temp = "lblF"&i
Item(i) = temp.text
Next
Of course this does not work, temp is a string not the name of the label.
Is there a simple way to use/convert the string as/to the name of the label?
I could go down the path of:
If i = 0 then Item(i) = lblF0.text
If i = 1 then ........
You can't 'Build' the variable name from text, you can get something similar.
Try This:
B4X:
Dim LblF() as Label = Array as Label(LblF0,LblF1,LblF2,LblF3,LblF4,LblF5.LblF6,LblF7,LblF8,LblF9,LblF10,LblF11,LblF12,LblF13,LblF14,LblF15)
For i = 0 to LblF.Length - 1
Log(lblF(i).Text)
Next
You can't 'Build' the variable name from text, you can get something similar.
Try This:
B4X:
Dim LblF() as Label = Array as Label(LblF0,LblF1,LblF2,LblF3,LblF4,LblF5.LblF6,LblF7,LblF8,LblF9,LblF10,LblF11,LblF12,LblF13,LblF14,LblF15)
For i = 0 to LblF.Length - 1
Log(lblF(i).Text)
Next
Error at line 9 ??
I have failed to initialize lblF(). Tried in code, tried in designer.
java.lang.RuntimeException: Object should first be initialized (Label).:
Sub Globals
....stuff
Dim LblF() As Label = Array As Label(lblF0,lblF1,lblF2,lblF3, lblF4,lblF5 , lblF6,lblF7,lblF8,lblF9,lblF10,lblF11,lblF12,lblF13,lblF14,lblF15)
End Sub
Sub FNumSelect
For i = 0 To 15
Log(LblF(i).Text)
Next
End Sub
Private LblF() As Label 'in Globals
Then after you load the layout in Activity_Create: You put the below line:
LblF =Array As Label(lblF0,lblF1,lblF2,lblF3,lblF4,l................
Private LblF() As Label 'in Globals
Then after you load the layout in Activity_Create: You put the below line:
LblF =Array As Label(lblF0,lblF1,lblF2,lblF3,lblF4,l................
You can't 'Build' the variable name from text, you can get something similar.
Try This:
B4X:
Dim LblF() as Label = Array as Label(LblF0,LblF1,LblF2,LblF3,LblF4,LblF5.LblF6,LblF7,LblF8,LblF9,LblF10,LblF11,LblF12,LblF13,LblF14,LblF15)
For i = 0 to LblF.Length - 1
Log(lblF(i).Text)
Next