Nested table initialization

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • guryev
    Indigo Rose Customer
    • Nov 2013
    • 4

    Nested table initialization

    Hello,

    Suppose I want to initialize an array consisting of tables in the Setup Factory script.
    Can I write something like:

    required_fields = {
    { id = CTRL_EDIT_01, description = "Company Name" },
    { id = CTRL_EDIT_02, description = "First Name" },
    { id = CTRL_EDIT_04, description = "Last Name" }
    };

    and then, for instance, access an element as:

    required_fields[ 2 ].id

    ?

    Thanks
  • Ulrich
    Indigo Rose Staff Member
    • Apr 2005
    • 5131

    #2
    Associative arrays may not keep the order as you expect, so the second element may not refer to CTRL_EDIT_02 after the initialization. However, there is actually no need to use an associative array here, because the control ids are numbers. You could simply use this:
    Code:
    required_fields = {};
    required_fields[CTRL_EDIT_01] = "Company Name";
    required_fields[CTRL_EDIT_02] = "First Name";
    required_fields[CTRL_EDIT_04] = "Last Name";
    Ulrich

    Comment

    Working...
    X