Variables
Description
Simple, scalar variables are declared using the keyword var. Special modifiers can be added to specify the type:
- dbl for floating point (extended precision),
- int for integer,
- str for strings;
Untyped variables are declared without a modifier, and can hold any type of data (dbl, int or str). However, mathematical expressions containing untyped variables execute more slowly.
Multidimensional variables are of two types, declared with either vars or array. Type modifiers (dbl, int and str) can be used with both vars and array.
- Variables declared as vars can have only one or two dimensions. Each element is an object in itself, and has all the properties and methods of a scalar variable declared with var
- Variables declared as array can have up to 10 dimensions. There is only one object holding the array data.
The array variables can be dimensioned when declared, and can be redimensioned at run-time. The vars variables are dimensioned when declared.
Parameters are special variables that are user-interactive. Scalar parameters are declared with par, while multidimensional parameters are declared with pars (equivalent to vars; there is no array equivalent). Type modifiers can be used (dbl, int, and str).
Like variables, parameters can be initialized in the code, when declared. The Script window has a special parameter editor (Parameters) where the values of parameters are displayed, and where they can be modified by the user. Typically, parameter values can be entered using the text editor. Additionally, a type modifier (slider) can be used when declaring a par or pars to activate a slider bar that can be used to modify the value of a parameter.
Declaring variables
var [{dbl|int|str}] Name [= Value];
vars [{dbl|int|str}] Name[Count[, Count]];
par [{dbl|int|str}] [{live|nolive}] [{store|nostore}] [{slider|noslider}] Name [= Value];
pars [{dbl|int|str}] [{live|nolive}] [{store|nostore}] [{slider|noslider}] Name[Count[, Count]];
array [{dbl|int|str}] Name[Low1, High1, Low2, High2, ...];
The live modifier causes a parameter (par or pars) to be periodically refreshed in the Parameters window. Without this, the parameters are refreshed only when the main script is stopped or paused, or programmatically with a call to the refresh method.
The store modifier causes a parameter (par or pars) to be stored in the Chart data whenever its value is changed interactively (or programmatically?).
The slider modifier activates a slider in the Parameter window, which can be used to interactively modify a parameter.
Properties
Inherited from Object
Inherited from Object
Inherited from Object
Array, Vars
Array
Array
Vars
If the argument is missing, it returns the total number of elements.
Par
d = rangedefined; |
rangedefined = d; |
Par
d = rangedefault; |
rangedefault = d; |
Par
m = rangemin; |
rangemin = m; |
Par
m = rangemax; |
rangemax = m; |
Par
l = rangelog; |
rangelog = l; |
Par
c = rangecount; |
rangecount = c; |
Methods
Inherited from Object
The argument refobj must be of the same type. If no argument is given, the reference is removed.
When a variable refers to another variable, calling its methods or properties and reading or writing its value always apply to the variable referenced.
An element of a vars or pars can be referenced, while an element of an array cannot.
Since the KPL language currently doesn't allow constructs such as MyVar[Index1, Index2].method,
a reference can be used to call the methods of individual elements of multidimensional variables.
For example, the following construct:
RefVar.setreference(MulVar[0, 1]);
RefVar.loadfromfile(FileName);
RefVar.setrefrence;
will load data from file into MulVar[0, 1].
Inherited from Value
loadfromfile(filename = f, binary = b); |
Inherited from Value
savetofile(filename = f, append = a, binary = b); |
Array
redim(low1, high1, low2, high2, ...); |
The maximum number of dimensions is 10.
Vars
s = sum(row1, row2, col1, col2); |
Vars
a = avg(row1, row2, col1, col2); |
Vars
s = std(row1, row2, col1, col2, avg); |
Vars
m = min(row1, row2, col1, col2); |
Vars
m = max(row1, row2, col1, col2); |
Par
setrange(default = d, min = m, max = x, log = l, count = c); |
Par
setrangebool(default = d); |
Par
Constants
Examples
See also
(C) 2008-2010 Lorin Milescu. Last modified: 08-26-2010