SVB: Array variable indexing

SVB: Array variable indexing

book

Article ID: KB0080539

calendar_today

Updated On:

Products Versions
Spotfire Statistica 13.0 and higher

Description

This article introduce how Array variable index its elements in a SVB or macro code.

For example, 

Dim a(3)

a(0) = 0

a(1) = 123

a(2) = 456

a(3) = 789

Environment

Windows

Resolution

1. When an array variable is declared, the number specified within the bracket () refers to the last element index of the array variable. 

e.g. Dim a(3)

This is to declare that the Array variable "a" has a maximum index number of 3. Last element of variable "a" is a(3). 

2. By default, all Array variable indexing starts from 0. Therefore, the total number of elements for an array variable is one greater than the number specified in the bracket () when an array variable is declared. 

e.g. Dim a(3)

That is, the array variable "a" by default will have 4 elements: a(0), a(1), a(2), a(3). 

3. To make the array variable indexing starts from 1 instead of 0, one need to add a declaration line in the Declaration section of the SVB script: 

Option Base 1

By adding this declaration line, the array indexing will start from 1. The total number of elements for the array variable will be the same as the number specified in the bracket () when the array variable is declared. 

e.g.  Option Base 1

Dim a(3)

In such way, there will only be 3 elements for array variable "a": a(1), a(2), a(3). 

4. For more information on Array declaration and indexing, please visit our online help page on array indexing in SVB code.

Issue/Introduction

SVB: Array variable indexing