variable members, variable names

Prev Next

Function Names

variable members, variable names

Description

The function variable members lists all member values of the array or structure in a set.
The function variable names lists all member names of the structure in a set. For obvious reasons, this function will not work with arrays.

Hint: Use the function flat() to remove any nesting in generated sets.

Call as: function

Restrictions

Indirect parameter passing is disabled

Parameter count

1-3

Parameters

No.TypeDescription
1
code
variable
:string
Variable name

2
input
numeral Level

0: All valid contents (except voids) of members and sub-members will be returned. Sub-members will be packaged in nested paramter sets.
1: Direct members only (children)
2: All sub-members only (grandchildren)
3, 4, ...: All deeper sub-members according to the level specified.

Default value: 0
3
input
string Option

Only supported value: all.
It forces all data, including voids to be included. If not specified, void data will be skipped. This applies to both variable members and variable names names.

Default value: (nothing specified)

Return value

TypeDescription
set Extracted values or names

Examples

       Hi[ German ] = Hallo; Hi[ German, in Switzerland ] = Grüezi;
       Hi[ German, in Bavaria ] = Grüss Gott;
       Hi[ French ] = Allô; Hi [ English ] = Hello;
       Hi[ Spanish, on the Phone ] = Diga;

       v[] = variable members( Hi[ ] );
       n[] = variable names( Hi[ ] );
       echo("Names : ", n[]);
       echo("Values: ", v[]);
       echo;

       // Include 'invalid value' in Hi[Spanish].
       v[] = variable members( Hi[ ], 0, all );
       n[] = variable names( Hi[ ], 0, all );
       echo("Names : ", n[]);
       echo("Values: ", v[]);
       echo;

       // Only 2nd level (like in Bavria ...)
       v[] = variable members( Hi[ ], 2 );
       n[] = variable names( Hi[ ], 2 );
       echo("Names : ", n[]);
       echo("Values: ", v[]);

Output

Names : {'English','French','German',{'in Bavaria','in Switzerland'},{'on the Phone'}}
Values: {'Hello','Allô','Hallo',{'Grüss Gott','Grüezi'},{'Diga'}}

Names : {'English','French','German',{'in Bavaria','in Switzerland'},'Spanish',{'on the Phone'}}
Values: {'Hello','Allô','Hallo',{'Grüss Gott','Grüezi'},# Invalid Value #,{'Diga'}}

Names : {{'in Bavaria','in Switzerland'},{'on the Phone'}}
Values: {{'Grüss Gott','Grüezi'},{'Diga'}}
Try it yourself: Open LIB_Function_variable_members.b4p in B4P_Examples.zip. Decompress before use.

See also

dim
array
structure
member count