Applies To:
  • CitectSCADA 5.xx, 6.xx
  • CitectHMI 5.xx, 6.xx


I need to store more elements in an array than Citect allows (Q1128).


I need to have local arrays in my Cicode functions, but Cicode only allows module and global arrays. What are the alternatives?


How can I return multiple values from a function?



Citect Queues can be used to solve these data storage problems. Queues can be dynamically created and destroyed. They are referenced by a handle so they can be passed to other functions, and other instances of the same function can have different data. By setting the citect.ini parameter [Code]Queue=-1 they have unlimited length. The drawback is that the more elements they contain, the slower they become.

Table Functions' Usage

The attached Cicode file contains a set of functions that use Citect queues to hold tables of data. To use them, you need to create the table (TableCreate() function), add items to it (TableSet), read them back (TableGet), and finally destroy the table (TableClose) when it's no longer needed. For example:

INT hTable; // Handle for the table
STRING sValue = "Some value to store";
STRING sRead; // Value read from the table
INT nElement = 1;

hTable = TableCreate();
TableSet(hTable, nElement, sValue); // Store the value
sRead = TableGet(hTable, nElement); // Read the value back

Table Sorting

These functions could be used with the sorting algorithms in Q3750. However, using multiple arrays provides better performance. With 479 strings, queues took about 3x as long as arrays (tested with the Shell sort algorithm). With 5,000 elements, queues took about 65x as long as arrays. Since Cicode arrays only hold 128 character strings and queues hold 256 character strings, there may be some cases where arrays would not be usable so a queue sorting function is included below.

Table Viewing

Another use for these functions is for viewing normal arrays during debugging. The Cicode Editor does not display the values stored in arrays, but you can copy all the elements to a queue and view it in the Citect Kernel. To view the table, go to the Main window in the Kernel and type PAGE QUEUE <Enter>. Press <Page Down> until the table name appears. By default, tables will all be named 'TableQueue'. It will be listed after all the tables Citect uses internally. Use the arrow keys to scroll through the values. Note: the element numbers display in hexadecimal and only the first 32 characters of each string are displayed.

For example, you could add this code fragment to your function to display the first 100 values that are in an array named mrProcessEvents:

INT hTable = TableCreate("ProcessEvents");

INT iCount;

FOR iCount = 0 TO 99 DO

TableSet(hTable, iCount, mrProcessEvents[iCount], TRUE);


After viewing it, make sure to call TableClose(hTable) to destroy it.

Table Cicode Functions

Add the attached Cicode file to your project to use the table functions.