controls in B4A

micro

Well-Known Member
Licensed User
Longtime User
What's the equivalent code in B4A?
This in Basic4ppc:
For i = 1 to 10
Control("butt" & i, Button).Visible = False
next

In B4A the Tag for the buttons is from 1 to 10
Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
There are several ways to achieve it.
You can add all those buttons to a list and then go over the list.
If you want to hide all buttons you can use Is:
B4X:
[COLOR=Black]For[/COLOR][COLOR=Black] i = [/COLOR][COLOR=Black]0[/COLOR][COLOR=Black]To[/COLOR][COLOR=Black] Activity.NumberOfViews - [/COLOR][COLOR=Black]1[/COLOR][COLOR=Black]
If[/COLOR][COLOR=Black] Activity.GetView(i) Is [/COLOR][COLOR=Black]Button[/COLOR][COLOR=Black] Then[/COLOR][COLOR=Black] 
 Activity.GetView(i).Visible = False
[/COLOR][COLOR=Black]End [/COLOR][COLOR=Black]If 
[/COLOR][COLOR=#0000ff][COLOR=Black]Next
[/COLOR]
Or you can write something like:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    For i = 0 To Activity.NumberOfViews - 1
        Dim tag As String
        tag = Activity.GetView(i).Tag
        If tag.StartsWith("butt") Then Activity.GetView(i).Visible = False
        'if you want to access a button specific method:
'        If tag.StartsWith("butt") Then
'            Dim b As Button
'            b = Activity.GetView(i)
'            b.
'        End If
    Next
End Sub
[/COLOR]
 
Upvote 0
Top