Getting names of controls

BjornF

Active Member
Licensed User
Is there an easy way of getting the names of all the controls on a form at once?

GetControls() only get the names of the controls which have the form as parent, so if you as I use panels to minimize the number of forms then you will need to go through each control and see if they are parents of controls in their turn etc.

all the best / Björn
 

Erel

Administrator
Staff member
Licensed User
First you can use GetControls("") to get all the controls.

Using the fact that panels controls can't be nested you can use the following code (it will add all controls on Form1 to the ArrayList named al1).
B4X:
Sub Globals
    'Declare the global variables here.
    Dim crl(0),tmp(0)
End Sub

Sub App_Start
    Form1.Show
    AddArrayList("al1")
    crl() = GetControls("Form1")
    For i = 0 To ArrayLen(crl())-1
        al1.Add(crl(i))
        If ControlType(crl(i)) = "Panel" Then
            tmp() = GetControls(crl(i))
            For x = 0 To ArrayLen(tmp())-1
                al1.Add(tmp(x))
            Next
        End If
    Next
    
    'Show the controls
    For i = 0 To al1.Count-1
        Msgbox(al1.Item(i))
    Next
End Sub
 
Top