Calculator object


Calculator

Basic code examples

Simplest case


Fig. 1: Simplest case
The example shows the basic usage of input/output variables. They can normally be used like normal C-style variables. In the example 5 is added to the input variable hugo and assigned to the output variable hugoout.

Array variables


Fig. 2: Array variables
In the example the elements of two floating point array input variables are multiplied and assigned to an output variable array. The command outarray.setSize(len) can be omitted but this leads to a slow down as each time a nonexisting element is addressed the array is extended.

After that to each element of the output array 2.5 is added. The +=, -=, /=, and *= operators apply the operation to each element of the array.

The example is safe: if the second array inarray2 is shorter than the first array inarray the second array is automatically extended and new elements are initialized with the default value 0.0.

String variables


Fig. 3: String variables
In the example is checked whether the input string contains a slash as last character which is appended if it is missing. If the string is empty on entry, it is set to "/.". After the changes the string is passed to the output variable.

The example demonstrates accessing single characters of a string as well as concatenating strings.

General comments

Global variables or constants defined outside the function run() are initialized on execution start. If characters are written to the standard output it appears in the message window for the case the GUI is running. Reading from standard input only works if programs are run without GUI, using the command vfl --exec ....

Command line parameters can be accessed using the global variables

int Argc; char* Argv[]; They contain exactly the parameters vfl's main function got at startup. The parameters have the common meaning that Argc has the number of parameters given at program start and the array Argv[] contains each parameter. The parameters are always "--exec" and "--link" when the execution of the GUI version is started.
Back


The Vimms User Manual