Programmer Guide/Shell Items/Table/Introducing Table Items: Difference between revisions
m (1 revision: Initial import) |
|||
(38 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:{{SUBPAGENAME}}}} | {{DISPLAYTITLE:{{SUBPAGENAME}}}} | ||
{{Table_Item_Template}} | |||
The {{STX}} table item is designed to store string or numerical data in rows and columns. The table item provides search and comparison functions. | |||
==Kinds of Tables== | |||
===Simple Table=== | |||
Simple tables store every entry as a string. There are no columns or fields. Case-sensitive character searching is supported as well as entry tagging. The show and write format have no relevance for simple tables. | Simple tables store every entry as a string. There are no columns or fields. Case-sensitive character searching is supported as well as [[#ckgtagged|entry tagging]]. The [[#ckgformats|display formats]] (''show'' and ''write'' format) have no relevance for simple tables. | ||
;Simple Table Example: This example demonstrates basic use of a simple table item. | |||
<pre style="margin-left:1.5em;"> | |||
<pre> | |||
[macro simple_table_example] | [macro simple_table_example] | ||
// | // | ||
Line 39: | Line 38: | ||
exit | exit | ||
</pre> | </pre> | ||
Extended | ===Extended Table=== | ||
Extended tables are able to store data of mixed types (integers, floating-point numbers, strings, and {{STX}} names) in one or more columns, each column being also known as a field. Fields may be assigned names which, in turn, may be used for accessing the content of the respective field. Regardless of a field being assigned a name, its content may always be referred to by its zero-based index. | |||
#value := [[Programmer_Guide/Command_Reference/SET|<code>set</code>]] $#table[$#entryIndex,$#fieldName] | |||
or | or | ||
#value := [[Programmer_Guide/Command_Reference/SET|<code>set</code>]] $#table[$#index,$#fieldIndex] | |||
In other words, you can access any value in a table with the following syntax: | In other words, you can access any value in a table with the following syntax: | ||
#value := [[Programmer_Guide/Command_Reference/SET|<code>set</code>]] $#table[$#row,$#col] | |||
The extended table makes use of the show and write format to format the data for the screen and for reading and writing the data to file. | The extended table makes use of the show and write format to format the data for the screen and for reading and writing the data to file. | ||
Note the use of the keyword | Note the use of the keyword [[Programmer_Guide/Command_Reference/SET|<code>set</code>]], safeguarding against the possibility that the value being returned is an {{STX}} keyword. Should that be the case, omitting <code>set</code> would cause the respective command to be executed - most likely ''not'' the desired effect. | ||
This example demonstrates basic use of an extended table item. | ;Extended Table Example: This example demonstrates basic use of an extended table item. | ||
<pre> | <pre style="margin-left:1.5em;"> | ||
[macro extended_table_example] | [macro extended_table_example] | ||
// | // | ||
Line 101: | Line 101: | ||
exit | exit | ||
</pre> | </pre> | ||
===Parameter Table=== | |||
Parameter tables are an optimized variant of the extended table restricted to storing numerical data only (integer and floating-point). Otherwise, they behave exactly like the normal extended table. | |||
This example demonstrates basic use of a parameter table item. | ;Parameter Table Example: This example demonstrates basic use of a parameter table item. | ||
<pre> | <pre style="margin-left:1.5em;"> | ||
[macro parameter_table_example] | [macro parameter_table_example] | ||
// | // | ||
Line 137: | Line 136: | ||
exit | exit | ||
</pre> | </pre> | ||
A table designed to be used to manage sound file information. On creation, fields for the sound file name, beginning and length of the sound file are automatically created. This type of table can be used with the <code>LOAD SOUNDFILE</code> command. | ===Soundfile Directory Table=== | ||
A table designed to be used to manage sound file information. On creation, fields for the sound file name, beginning and length of the sound file are automatically created. This type of table can be used with the [[Programmer_Guide/Command_Reference/LOAD#LOAD_SOUNDFILE|<code>LOAD SOUNDFILE</code>]] command. | |||
== {{anchor|ckgformats|Display Formats}} == | |||
=== | ===The Show Format=== | ||
A table can be configured to display it's data using a c-style format string. This format is called the 'show' format and is used by the listbox and listview dialog controls when displaying table data. See Configuring a table field for details. | A table can be configured to display it's data using a c-style format string. This format is called the 'show' format and is used by the listbox and listview dialog controls when displaying table data. See [[Programmer_Guide/Shell_Items/Table/SET_TABLE#Configuring_a_table_field|Configuring a table field]] for details. | ||
=== | ===The Write Format=== | ||
In addition to the show format, a table also has a configurable format for reading from and writing to file; this is called the 'write' format. See Formatting table fields for configuration details. | In addition to the show format, a table also has a configurable format for reading from and writing to file; this is called the 'write' format. See Formatting table fields for configuration details. | ||
Note that the show format can also be used to read from and write to file, if so configured (see the <code>MODE</code> command).== | Note that the show format can also be used to read from and write to file, if so configured (see the <code>MODE</code> command). | ||
=={{anchor|ckgtagged|Tagged and untagged table entries}}== | |||
Entries in a table can be either tagged or untagged. By default every entry is untagged. A table can be configured to display tagged entries only (see showing and hiding table entries). If so configured, untagged entries cannot be accessed, deleted or displayed (e.g. in a dialog listbox). | Entries in a table can be either tagged or untagged. By default every entry is untagged. A table can be configured to display tagged entries only (see showing and hiding table entries). If so configured, untagged entries cannot be accessed, deleted or displayed (e.g. in a dialog listbox). | ||
Line 157: | Line 161: | ||
You can switch between table modes displaying all entries (<code>$#table /All</code>) and only tagged entries (<code>$#table /T</code>). | You can switch between table modes displaying all entries (<code>$#table /All</code>) and only tagged entries (<code>$#table /T</code>). | ||
==Selected Entries== | |||
When a table is used in conjunction with a dialog control (e.g. a listbox), tagged entries are displayed as selected entries. | When a table is used in conjunction with a dialog control (e.g. a listbox), tagged entries are displayed as selected entries. You can retrieve the number of selected entries with <samp>$#table[!TAGGED]</samp>. If you would like to retrieve the selected entries, you must hide non-selected entries (<samp>$#table /tagged</samp>) and then you can loop through the visible rows. | ||
==Counting Table Entries== | |||
There are two ways to retrieve the number of table entries: | There are two ways to retrieve the number of table entries: | ||
$#table[!nrow] | |||
or the special syntax | or the special syntax | ||
$#table[] | |||
==Assigning table entries== | |||
You can assign values to table entries by using the SET table command or by using the assignment operator. | You can assign values to table entries by using the [[Programmer_Guide/Shell_Items/Table/SET_TABLE#Setting_or_Adding_table_entries|<code>SET table</code>]] command or by using the assignment operator. | ||
Here are some examples | Here are some examples: | ||
// assign a string to the second entry, using the assignment operator | |||
// assign a string to the second entry | $#table[1] := set 'a string value' | ||
$#table[1] := set 'a string value' | |||
// remove all entries and assign this number to | // assign a string to the fifth entry, using the SET command | ||
// the first entry | SET $#table 1 'another string value' | ||
$#table := 1000 | |||
// append this number to the table | // assigning a string to the eleventh entry, using the implicit SET command | ||
$#table[$#table[]] := 1001 | $#table 1 'yet another string!' | ||
// remove all entries and assign this number to | |||
// the first entry | |||
$#table := 1000 | |||
// append this number to the table | |||
$#table[$#table[]] := 1001 |
Latest revision as of 09:06, 13 December 2018
Table Item | |||
---|---|---|---|
INTRODUCTION | NEW | SET | ATTRIBUTES |
The STx table item is designed to store string or numerical data in rows and columns. The table item provides search and comparison functions.
Contents
Kinds of Tables
Simple Table
Simple tables store every entry as a string. There are no columns or fields. Case-sensitive character searching is supported as well as entry tagging. The display formats (show and write format) have no relevance for simple tables.
- Simple Table Example
- This example demonstrates basic use of a simple table item.
[macro simple_table_example] // // create a simple table item // #t := new table * if '$#t[?]' != 'table' em $RC ; $EMSG // // add some data // $#t * 'the first entry' $#t * 'the second entry with some numbers - 0, 1, 2, 3' $#t * 'the third entry' // // remove some data // $#t 0 /Delete // remove the first line // // display the table contents // showitem $#t // // clean up // delete $#t exit
Extended Table
Extended tables are able to store data of mixed types (integers, floating-point numbers, strings, and STx names) in one or more columns, each column being also known as a field. Fields may be assigned names which, in turn, may be used for accessing the content of the respective field. Regardless of a field being assigned a name, its content may always be referred to by its zero-based index.
#value := set
$#table[$#entryIndex,$#fieldName]
or
#value := set
$#table[$#index,$#fieldIndex]
In other words, you can access any value in a table with the following syntax:
#value := set
$#table[$#row,$#col]
The extended table makes use of the show and write format to format the data for the screen and for reading and writing the data to file.
Note the use of the keyword set
, safeguarding against the possibility that the value being returned is an STx keyword. Should that be the case, omitting set
would cause the respective command to be executed - most likely not the desired effect.
- Extended Table Example
- This example demonstrates basic use of an extended table item.
[macro extended_table_example] // // create an extended table item // #t := new table * * /Extended string:str integer:int number:num if '$#t[?]' != 'table' em $RC ; $EMSG // // add some data // $#t * str 'first' int 1 num 2.3 $#t * str 'second' int 2 num 4.7 $#t $#t[] str 'third' int 3 num 5.9 $#t $#t[!nrow] 'fourth' $#t 5 str 'sixth' int 6 num 9.9 // 5th entry is left empty // // remove some data // $#t 0 /Delete // remove the first line // // display the table contents // showitem $#t // // format data and redisplay // $#t config str 1 0 1 '%.5s ' * * * 'string' 8 if '$rc' > 0 em $rc ; $EMSG $#t config int 0 // hide 'int' column if '$rc' > 0 em $rc ; $EMSG $#t config num 1 1 2 '%f' 1 -1 * 'number' 8 if '$rc' > 0 em $rc ; $EMSG // // display the table contents // showitem $#t // // clean up // delete $#t exit
Parameter Table
Parameter tables are an optimized variant of the extended table restricted to storing numerical data only (integer and floating-point). Otherwise, they behave exactly like the normal extended table.
- Parameter Table Example
- This example demonstrates basic use of a parameter table item.
[macro parameter_table_example] // // create an extended table item // #t := new table * 10 /P if '$#t[?]' != 'table' em $RC ; $EMSG // // add some data // // initialize 10x10 matrix $#t := eval init($#t[!ncol],$#t[!ncol],0) // replace first line $#t[0,*] := eval fill(10,0,1) // replace fifth column $#t[*,4] := eval fill(10,$#t[0,4],1) // transpose the matrix $#t := eval trn($#t) // // display the table contents // showitem $#t // // clean up // delete $#t exit
Soundfile Directory Table
A table designed to be used to manage sound file information. On creation, fields for the sound file name, beginning and length of the sound file are automatically created. This type of table can be used with the LOAD SOUNDFILE
command.
Display Formats
The Show Format
A table can be configured to display it's data using a c-style format string. This format is called the 'show' format and is used by the listbox and listview dialog controls when displaying table data. See Configuring a table field for details.
The Write Format
In addition to the show format, a table also has a configurable format for reading from and writing to file; this is called the 'write' format. See Formatting table fields for configuration details.
Note that the show format can also be used to read from and write to file, if so configured (see the MODE
command).
Tagged and untagged table entries
Entries in a table can be either tagged or untagged. By default every entry is untagged. A table can be configured to display tagged entries only (see showing and hiding table entries). If so configured, untagged entries cannot be accessed, deleted or displayed (e.g. in a dialog listbox).
You can tag or untag individual entries with the command $#table $#index /Tag
or $#table $#index /Untag
.
You can switch between table modes displaying all entries ($#table /All
) and only tagged entries ($#table /T
).
Selected Entries
When a table is used in conjunction with a dialog control (e.g. a listbox), tagged entries are displayed as selected entries. You can retrieve the number of selected entries with $#table[!TAGGED]. If you would like to retrieve the selected entries, you must hide non-selected entries ($#table /tagged) and then you can loop through the visible rows.
Counting Table Entries
There are two ways to retrieve the number of table entries:
$#table[!nrow]
or the special syntax
$#table[]
Assigning table entries
You can assign values to table entries by using the SET table
command or by using the assignment operator.
Here are some examples:
// assign a string to the second entry, using the assignment operator $#table[1] := set 'a string value' // assign a string to the fifth entry, using the SET command SET $#table 1 'another string value' // assigning a string to the eleventh entry, using the implicit SET command $#table 1 'yet another string!' // remove all entries and assign this number to // the first entry $#table := 1000 // append this number to the table $#table[$#table[]] := 1001