Error Messages/40616
Error message examples
You cannot assign to a slice or subscript of a global variable object.
Cause
Analytica won't let you assign a value to a slice (subscripted element) of a global variable, even in an OnClick or OnChange attribute, or Function called from one of those, where you would normally be able to assign to a global variable. It will let you assign to a slice of a local variable.
Here the OnClick attribute of Button Change_X
tries to assign to a slice of the global variable X
, and so triggers this error message:
Index I := 1..2 Variable X := Table(I)(10, 20) Button <code>Change_X</code> OnClick: X[I = 2] := 30
Remedies
Analytica does let you assign to a slice of a local variable (in any Definition), and it does let you assign to a global variable (not a slice) in an OnClick or OnChange attribute, or Function called from one of those attributes. So you can work around this problem.
- Copy the global array,
X
, into a local variable,local_x
, - Assign a new value to a slice of
local_x
, - Assign the value of
local_x
back to the global,X
,
For example:
Index I := 1..2 Variable X := Table(I)(10, 20) Button <code>Change_X</code> OnClick: VAR local_X := X; local_X[I = 2] := 30; X := local_X
This does what you need.
See Also
Comments
Enable comment auto-refresher