Label Text Naming

metrick

Active Member
Licensed User
Longtime User
How can I change the name(text) of each labels with for loop.
eg. I have named labels as followings;
lb_0 to lb_45
I was thinking something like this, but I got an error.

for i = 0 to 45
lb_(i).text = "Sometext" & strVal & i
next
 

rbsoft

Active Member
Licensed User
Longtime User
Based on this thread http://www.b4x.com/forum/basic4android-updates-questions/13426-views-array.html#post75724 I made a small project that might do what you expect.

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

   Dim lbl_0 As Label
   Dim lbl_1 As Label
   Dim lbl_2 As Label
   Dim Button1 As Button
   Dim lbl() As Label    
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout(1)
   lbl = Array As Label(lbl_0, lbl_1, lbl_2)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Button1_Click
   'Dim lbl As String 
   Dim i As Int
   Dim t As Object 
   
   For i = 0 To 2
      lbl(i).text = "Label" & i
   Next
End Sub

Hope this helps.

Rolf
 

Attachments

  • LabelArray.zip
    6.2 KB · Views: 181
Upvote 0
Top