StorageArray
StorageArray
StorageArray is a shared ArrayList collection used to temporarily store data, objects, or state information between your scripts or between different executions of the same script.
Normally, scripts start from scratch (variables are reset) every time they run (trigger). StorageArray sits outside this lifecycle, allowing the script to carry its “memory” over to the next execution.
Key Features
- Temporary Memory
All data within StorageArray is stored only as long as SCADA Runtime is open. When Runtime is closed or restarted, this collection is reset, and all data is lost. For permanent storage, Historical Tags or a database should be used. - Empty Start
When SCADA Runtime runs for the first time, the size (Count) of the StorageArray collection is zero (0). - Shared Access
Data added to StorageArray by one script can be read or modified by another script. This acts as a bridge for inter-script communication. - Flexible Types (Heterogeneous)
Since it is a standard ArrayList, you can add different types of data into the collection. For example, you can add a boolean (true/false) first, and then an integer (number).
Definition (Adding to Script)
To use StorageArray within a script, you must define it as a public variable inside your MainClass.
| C# | public ArrayList StorageArray; |
| VB | Public StorageArray As ArrayList |
Example 1: Simple Counter (Incrementing Value on Each Run)
This example allows a script to count how many times it has run since Runtime started.
Scenario: When the script runs for the first time (StorageArray.Count == 0), it adds the value 1 to the collection. In every subsequent run, it reads this value, increments it by 1, and writes it back.
C# Code:
public class MainClass
{
  public ArrayList StorageArray;
  public void Main()
  {
    // 1. Check: Is the Array empty?
    if(StorageArray.Count == 0)
    {
      // 2. Yes (First Run): Add initial value
      StorageArray.Add(1);
    }
    else
    {
      // 3. No (Subsequent Runs): Read current value
      MessageBox.Show(StorageArray[0].ToString());
      Â
      // 4. Increment by 1 and write back
      // (Read value is 'Object' type, must be cast to 'int')
      StorageArray[0] = (int)StorageArray[0] + 1;
    }
  }
}
VB Code:
Public Class MainClass
  Public StorageArray As ArrayList
  Â
  Public Sub Main
    ' 1. Check: Is the Array empty?
    If StorageArray.Count = 0 Then
      ' 2. Yes (First Run): Add initial value
      StorageArray.Add(1)
    Else
      ' 3. No (Subsequent Runs): Read current value
      MessageBox.Show(StorageArray(0).ToString())
      Â
      ' 4. Increment by 1 and write back
      StorageArray(0) = StorageArray(0) + 1
    End If
  End Sub
End Class
Example 2: Advanced Usage (Object Storage and Inter-Script Communication)
StorageArray can store not just simple numbers, but objects themselves (a Timer object, a Button object, etc.). This allows you to stop a process started in one script from another script.
Scenario: When a Timer starts, the Timer_0_Tick event triggers and saves the Timer object itself to StorageArray. Later, we run the Main() script by pressing a button; this script retrieves the Timer object from StorageArray and stops it (Enabled = false).
