set, set names

Prev Next

Function Names

set, set names

Description

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

Hint: Use the function flat() to remove any nesting in generated parameter 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 set and set names.

Default value: (nothing specified)

Return value

TypeDescription
parameter 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[] = set( Hi[ ] ); n[] = set names( Hi[ ] );
  echo("Names: ", n[]);
  echo("Values: ", v[]);

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

  // Only 2nd level (like in Bavria ...)
  v[] = set( Hi[ ], 2 ); n[] = set 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_set.b4p in B4P_Examples.zip. Decompress before use.

See also

dim
array
structure
member count