Android Question Labels as array

trepdas

Active Member
Licensed User
Hello.
I am very new in vb4a and still didn't get the idea of how to create an array from labels in vb4a

can anyone please give me the solution to this ?
with buttons I use Sender to determine which button was clicked but how do I do this with labels?

in vb6 I created 4 labels and it assigned the index into it. label1(1), label1(2),label1(3) and label1(4) in the form.

so how do I do this in vb4a ?

i = Int(Rnd(1) * 4) + 1
Label1(i).Caption = "X"

THANKS
 

jazzzzzzz

Active Member
Licensed User
Longtime User
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim label(10) As Label
    Dim y As Int
    y=0
    For i=0 To 2
        label(i).Initialize("label")
        label(i).Text = "label "& i
        label(i).tag = i
        Activity.AddView(label(i),0,y,50dip,50dip)
        y=y+60
    Next
End Sub

Sub label_Click
    Dim label As Label
    label = Sender
    If label.Tag = 0 Then
        label.Text = "Clicked "&0
    Else If label.Tag = 1 Then
        label.Text = "Clicked "&1
    Else If label.Tag = 2 Then
        label.Text = "Clicked "&2
    End If
End Sub

I assume above code explains how sender and tag works.
 
Upvote 0
Top