SIZE — Size In Elements

SIZE in rungs.dev counts the elements of an array and stores the count in a tag, so a rung never has to hardcode how long an array is.

SIZE

Array

array

Dimension

dimension

Destination

destination

Counts the elements of an array and stores the count in the destination tag.

What it does

SIZE keeps an array's length out of your logic. A rung written against a hardcoded 12 silently breaks the day someone resizes the tag to 20; a rung written against a SIZE result keeps working.

It reads nothing from inside the array — only how long it was declared — so it never faults and never touches the data.

Operands

NameTypeNotes
arrayany array tagThe array itself — Samples or Samples[0]
dimensionthe number 0Which dimension to measure
destinationDINT, INT, SINT, REALWhere the count goes

The whole array, not an element

Samples and Samples[0] both mean "the whole array". Samples[3] is refused — there is no such thing as the size of a run starting part-way along. That is the opposite of COP, where you must name one element.

dimension asks which dimension to measure. Studio supports single-dimension arrays only, so it is always 0.

A narrow destination wraps like any other store: a 300-element array counted into a SINT leaves 44, not 127.

Example — Loop to the End of the Array

0

Scan

SIZE

Array

Samples

Dimension

0

Destination

Count

1

LT

Source A

Index

Source B

Count

MoreToDo

Count always matches the array, so resizing Samples needs no change to the rung.

Structured Text

SIZE has a Structured Text form as well — see the Structured Text SIZE page.

On this page