Code written in CalcIt language can be as simple as a mathematical expression that returns a single numeric value or multi-statement code of any complexity. People with basic programming skills can use the full power of CalcIt language. If you ever had programmed in languages like BASIC or PASCAL, to program CalcIt will be no problem.
If CalcIt code is more than one expression then it is considered multi-statement. Every statement is separated by other statements using semi
colon character (;).
E.g.
a:=1000;
v:=a*56;
print(a+v);
Any piece of CalcIt code returns a value, numeric or alphanumeric. Any
expression which doesn't assigns its value to a variable (using
assignment operator (:=))
, defines or redefines
the return value of the code. E.g.
a:=1000;
v:=a*56;
print(a+v);
a+v;
In the above example the last statement (a+v) doesn't assign its value to any other variable and so defines or redefines the return value of the whole code. Many such statements can be executed in a code redefining always the return value of the code. We can read the current returned value using the command RESULT. E.g.
a:=1000;
v:=a*56;
print(a+v);
a+v;
RESULT*1000;
The last statement in the example above reads the current returned value of the executed code and multiplies it by 1000 and redefines again its returned value.
To add some comments in the text of a computation, we can use {}
symbols.
E.g. {This is a comment}
.
Using //
we can comment out the text after it in the same line.
E.g.
a:=1000; //assigns 1000 to the variable a
v:=a*56; //assigns a*56 (56000) to the variable v
print(a+v); //Prints in output window the value of expression a+v
(57000)
a+v; //Defines the return
value of the code as the result of expression a+v (57000)
RESULT*1000; //Redefines the return value of the code taking its previous
value (57000) and
//multiplies it by 1000. The new returned value is 57000000
Inside a piece of CalcIt code local functions can be defined using keyword function.
function
AddTwoNumbers(n1,n2);
n1+n2; //defines the returned
//value of the function
//as the sum of n1 and n2
end;
AddTwoNumbers(10,5); //returns 15 and defines
code's returned value
Inside local functions any change of RESULT refers to the returned value of the function and not of the whole CalcIt code.
Any number of variables can be created and used in CalcIt code if their names follow some conventions. There are seven kind of variables:
NOTES:
AnyFunc(1,,4,,5).
i:=IgnoreReturnedValue(10,200,300);
//the RESULT is not changed
noret IgnoreReturnedValue(10,200,300); //the
same but using NORET
Feature | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Dynamic Arrays | Any number of single dimensioned dynamic arrays can be created
and used in CalcIt code. The SET command is used
to define, redefine or assign values to a dynamic array. To create an
array with an initial specific size we use the following syntax:
The above syntax declares an array variable ar of 100
elements. This size can
be changed by the use of SET command again or other special commands that
Add, Insert or
Delete elements. For example Another way to declare/redefine/initialize an array is to use the SET command to load a text file on it very easily and in one step. E.g. We can easily declare/redefine/initialize an array with specific values in the following way:
Once an array variable is declared the assignment operator (:=) can be used as well, to assign the result of an array expression to the variable:
Every array element can be accessed for read or write using an index in parentheses:
The first statement changes the third (3) element of the array ar. The second reads and prints on output window the contents of the third (3) element of the array ar. NOTE: The index is one based, the first item is at index 1. To access an array in the reverse order a negative index can be used. For example ar(-1) accesses the last element of the array, and so on. Intersection, Union, Difference and Concatenation
operations can be
performed over whole arrays and
the use of symbols Inclusion operator IN can be used to check if a value is contained in an array. Additionally there are commands to search (SEARCH, BINSEARCH), sort (SORT, SORTN), summarize (SUM) the contents of array variables. See also commands MIN, MAX, AVRG, PRINTARR. Every array element can contain delimited text which can be accessed for read or write. E.g.
See more about this feature in Delimited Text. To Add, Insert or Delete elements from an array we use commands ARRADD, ARRBINADD, ARRINS and ARRDEL. A
quick syntax to add an element at the end of a dynamic array is
the one using a set of empty parentheses: The contents of an array can be written to disk as a text file using the WRITE or APPEND commands. The syntax below is valid:
Creates a new array with zero elements or empties (redefining) another previous declared. Check the special FOR loop syntax that is used exclusively to process dynamic arrays and offers speed and convenience. See also Fine tuning Dynamic arrays operation. Every array element is not limited to hold only one value. Can be extended to hold more using fields. See Using Fields below. See also Array Extensions on how every array element can be extended to contain another array. For extended array manipulation see also Array Expressions below and inline arrays |
||||||||||
Array Expressions | Array expressions look like normal CalcIt
expressions but instead of additions, subtractions etc over numeric or alphanumeric values,
whole arrays are used in a different set of operations.
The result of array expressions can be assigned in array variables (using SET command) or can be passed in functions array IN parameters. The
operations that can be performed in such expressions are:
e.g. where a, a1, a3, a4 are array variables. In the
example SET command is used to assign the result of the array expression (
In case of alphanumeric values the operations are not case sensitive. In case we want to add an array at the end of
another ( A number of functions that return arrays can be used in array expressions. These are:
NOTE: Commands LEFT, MID, RIGHT have alternatives that work with strings in string manipulation. The precedence of the operators used in array expressions is the same. Parentheses can be used where this is needed. See also about Inline arrays below. |
||||||||||
Inline arrays | Inline arrays are arrays represented by
their contents directly and not by some array variable. Inline arrays appear in the code as a list of simple expressions
separated by commas and enclosed by brackets. e.g.
The above represents an inline array of 5 elements which is used to initialize array variable ar. Every element can be the result of an expression. Inline arrays can participate normally in array expressions like anything is or returns an array. Inline arrays that contain only constant values are created at compile time and so introduce no performance penalty at run time. An example code:
Remember that sortn is for numerical sorting. TIP: Inline arrays can be used in case we need an interface of variable numbers of parameters in local functions and UDF. In a local function or UDF we can declare an array (IN) parameter. This parameter can accept an inline array:
NOTE: In array expressions of only one inline array that contains only one element, the brackets can be omitted. For example the following statement,
can be written as:
The same is valid for IN (by value) array parameters in local or standard functions. See also array expressions above. |
||||||||||
Fine tuning Dynamic arrays operation | Dynamic arrays is an
important part of the CalcIt language and an explanation of the way they
work is needed.
The main characteristic of the dynamic arrays is their ability to increase their size dynamically. The programmer can add any number of elements at any moment in a dynamic array. This is possible because CalcIt language reallocates the memory occupied by a dynamic array so the array is able to accommodate more elements. Every time a reallocation occurs the data existed in the previous allocation are copied to the new greater in size allocation. The reallocation operation is a very expensive operation in terms of execution time and memory. At the time of the reallocation an array has to occupy more that the double of the memory it is needed. Then a copy takes place to move data from the old allocation to the new which is very costly. The previous allocation, after the copy, has to be freed involving another access to the generally slow memory manager. Additionally the free memory pool is at risk to be fragmented and become unusable. For the above reasons CalcIt language tries to avoid frequent reallocation as possible. The technique used is simple. Every array reserves more elements than needed. This way when a new item is added to the array one of the preallocated reserved elements is used and the reallocation is avoided. The reallocation occurs when all the reserved space is exhausted. Every reallocation adds to the array the elements requested plus the reserved space. By default the reserved space is 500 elements. This in most codes is ok. But some times will prefer a different number. An array in local function which is reinitialized every time the local function is called is slower if it has to allocate every time 500 elements. We know that this space is never used so is possible to prefer a smaller number. Other times we have to add in a array a very big number of elements that we know is not bigger than a specific number. Then we prefer a reserved space equal to this number instead relying in too many reallocations that slow down the operation considerable and also, because of memory fragmentation, can cause a "memory full" error when plenty of memory seams available. Using the syntax below is possible to define array's reserved space size:
The above syntax defines (or redefines) an array variable a to ArrSize elements using ReservSpace elements reserved space. Both parameters are optional. If ReservSpace is not provided then 500 is assumed. An alternative syntax can be used, as well:
|
||||||||||
Using Fields | This feature added for reasons of code readability and flexibility. Applies
to every simple variable and array element. Every such variable/array element normally holds only one
value. But sometimes it is needed to keep in one such variable more than
one values through the use of fields. Better explain that with an example.
Handling Fields at Compile Time (when the field's name is known at compile time): Let's say, a variable MyComputer. With the assignment below it takes a value:
What if is needed to add more values in the variable MyComputer regarding our hard disk, keyboard, mouse, CPU etc, like subcategories of MyComputer? This is a nice case to use fields and add in one and only one MyComputer variable all these values:
Just using these assignments the fields Monitor, HD, Keyboard and CPU are created for the variable MyComputer and of course it is possible to refer to them the same way.
At the first writing to a variable's field, the field is created and the variable goes to a multi-value-field mode. It is possible to go back in a single value mode using again an assignment and not using fields any more:
In this assignment any field values will be destroyed and only one value will be forced for the MyComputer. The same happens in case of field assignments. Any previous single value is destroyed. Generally, copying a variable to another always makes a perfect copy whatever mode was the variable that receives the copy, before the copying. HINTS: Fields can be used to reduce the number of parameters in local functions or UDF. Many values can be passed in only one parameter. Especially, in case of one IN/OUT (by reference parameter) many values can be returned at once. Also a local function or UDF can return many values in its result. NOTE: It is possible to create fields on fields in an endless chain. For example:
This feature will be very useful and handy for array elements. Imagine an array where every element have a number of values accessed through the same fields. Of course every element can have different fields, there is no limitation here, but occasion to be such thing useful will be, probably, somewhat rare. In case of arrays the use of fields has some consequences. What happens with array expressions where array elements have different fields or participate arrays with different or no field structure at all? What about searching, sorting etc array with element in any field or not configuration? For the arrays only is introduced the concept of the default field. For every array variable can be defined a default field using the command SetArrField.
Lets explain the above code. There is an array variable Computer. We want to add elements where each one holds two values for always the same fields cpu and monitor. A local function (addv) helps this purpose. At every execution of addv is passed the Computers() (in the place of an IN/OUT parameter - observe symbol &). This syntax adds a new element to the array and returns it. So in every execution of addv a new elements is created, is passed to addv code and it is initialized in the two fields, cpu and monitor. So the above codes adds two elements. Command SetArrField sets the default field for Computer to be the field cpu. So the Sort command bellow will sort the array using the field cpu. The above code prints:
Really, the sorting is by cpu field. Lets now change the command SetArrField to set as default field the monitor.
The new execution of the code prints:
Indeed, the sorting is now by monitor field. All array expressions operators, sorting, searching and the UNIQUE command are affected by the selection of the default field. In case there are array elements with no field structure, then, their single value is always considered in the operation. In case of array expressions where two arrays participate through one of the operators (Intersection, union, etc) the resulting array has as default field the one of the first operant. It is possible to clear the default field with the following syntax:
In case there is a need to create an array with the values of one field of another, the command ArrCol can be used.
The field parameter is optional. If omitted then the default field will be used. To save and read back arrays with multi-field elements the commands XWrite and XRead can be used. Handling Fields at Run Time: The above description speaks about fields which their names are known at compile time. There is also the capability to create/access fields that are not known at compile time. In this case a special syntax is used to read or write to these fields. Lets say a variable vr. At run time a field computer is created/accessed with the following statement:
The syntax uses a DOT (like the compile time fields) and then follows an expression enclosed in parentheses which returns the name of the field. Commands specific to Fields handling Every field can be extended to contain an array. See more at Array extensions below. |
||||||||||
Array Extensions | Every simple variable,
array element or
field, can be extended to contain an array. This way very
complex hierarchical data structures can be created. Normally the compiler recognizes an array because a variable is declared as such through set command. In case of simple variables, array elements and fields, another way is needed to provide a similar distinction at compile time. So wherever any of the previous contains an array and has to be passed as a whole to a command or to participate in an array expressions, then the symbol @ is used to denote this. For example @a, where a is a simple variable, can be used like a declared array variable. @r(5) is an array element (of array variable r) that can be used as an array, by itself, in array expressions. The same with @a.f1 in case of a field (f1). The only exception is with set r(10) syntax (where any positive number can be in place of 10). In case of array extensions this syntax cannot be used. Use set @a=arr(10) in its place. To access one element at a specific index, the parentheses are used in exactly the same way as with declared arrays. For example if a is a simple variable then a(10) accesses the 10nth element of the array it contains. In case an array is not assigned to this variable before, then an error will stop the program at run-time. So parentheses with an index, applied directly to any simple variable, field or array element always mean access of an array element at the specified index. Exactly the same way as with declared array variables. This way very complex data hierarchies can be created and handled. Can be printed on screen through PrintArr command, saved to disk through XWrite and loaded back through XRead. let's say a is a simple variable. To be used as an array first must be initialized as as array. Assigning the result of an array expression is the more direct way:
In the above code first and second lines assign the result of an array expression to @a with two equivalent ways. The third line prints @a like it was an array variable. The fourth assigns to array variable x the result of an array expression where @a participates in an array concatenation operation.
The above code adds 1 on every element of the array contained in @a; The special array FOR syntax can be used, to the same purpose, in the code below:
In all these examples @a is used like any other usually declared array variable. Another example below demonstrating how an array element can be extended to contain another array and how in this case the individual elements are accessed.
The above code declares an array variable ar assigning to it the contents of an array expression (in this case is just an inline array). Then takes element at index 2 and overwrites its previous contents (previous value 200) to contain by itself an array, again assigning the contains of an array expression. Symbol @ is used to denote that this elements has to be handled like an array variable. Then adds 1000 to the third element of this new array. The rest of the lines of the above code prints the result of the root array variable ar and after that the contains of the array contained in its second element only. It prints:
NOTE: Through array extensions, functions can return arrays. |
||||||||||
Automation Objects | Through automation variables, objects exposed by
automation servers (like Excel) can be accessed.
This creates an Automation variable connected with the Excel application. Using o we can access Excel and "borrow" its functionality. E.g. When the Excel runs execute the code below.
The example above fills with numbers some cells of the active sheet. The SET command for automation first tries to connect in an instance of a server already running. If the requested server is not running then creates a new instance of it. Alternatively we can write
This creates a new "empty" automation variable. With the use of SET command we can assign to it content later in the code. This syntax creates "placeholders" for intermediate objects returned by properties or methods of automation objects that are objects too. To declare an automation variable and the same time assign to it an object returned by a property or method of another object, we can use the syntax below:
This will assign the Range object (in Excel) A1:A10 to the variable no. And so on. If the automation variable is already declared as such, is posible to use a simple assignment to pass a value to an automation variable:
We can create automation object variables through a automation object pointer returned by an imported (via DLL) routine using OBJP keyword:
We can pass automation objects in object methods that require such a parameter. We can denote omitted parameters simply placing only the comma (,) character. If a parameter in a method is IN/OUT, its value is not returned except we use the character & as the following text describes:
Lets say that the second parameter can return a value (IN/OUT parameter). With the above syntax this value will not be returned (but the value of v will be passed normally to the automation server). If we want to get the returned value then we can do that with the following syntax:
|
||||||||||
File Variables. | We can create File
variables that permit us to access for read or write any kind
of file.
Using a file variable we can access a file in many ways like an array (a memory object) either for read or write. This makes their use very convenient. This feature can be used to explore a file of any structure, to patch a file, use a file for persistence storage of the data we handle on it or create binary files of any structure and content. We declare a file variable simply using the SET command:
This creates (or redefines) a file variable named f. Using this variable we can access the file it points: 'c:\test.dat'. The access to this file can be read-only or read-write. This is defined by the second parameter which is optional. (Default is read-only, TRUE). In our example the access is read-write. The way to access the file is similar with arrays. We use an index:
With this statement we read a byte value (atBYTE) at index 100. The meaning of the index by default is a byte index from the start of the file (the first byte is at index 0). Its meaning can be changed using the command FileRecDef which helps to break the file in equal sized pieces of any size (records). Read more at Using File Variables topic. Whatever kind of indexing we accept or define eventually we will conclude in a byte index from the start of the file. There we can access for read or write the file using the syntax that the above example implies. The memory in the requested file position can be accessed as byte (in the example), as a word (atWORD), as double word (atDWORD), as integer (atINTEGER), as float (atFLOAT), as a string of a fixed size or as a null terminated string (of no fixed size) (atCHAR). These access types are fully explained at Using File Variables topic. To write a value in a file variable we make normal use of the assignment operator:
If variable f is not in read-only mode then the value of 230 will be written at position 100 of the file (zero-based index). NOTE: Because atBYTE is the default access type (if not altered by FileRecDef), can be omitted.
Here is a reference of commands used to handle binary files:
For a full description and tutorial of this feature see Using File Variables topic and alphabetical keywords list. NOTE: We can handle files of up to 2GB in size. |
||||||||||
Buffer Variables | Buffer variables is the only way, in
CalcIt, to access a piece of memory using "fields" of a specific
type, like integer type, string type, double type, etc.
For every Buffer variable exist two things:
The way we want to access a buffer is a number of fields of a specific type one after another. We call this group of fields a "structure". To define a structure definition we use the command BUFDEF:
The above defines a structure of three string fields of 30 character each. We can define fields of the following types:
BUFDEF command is always evaluated at compile time and so we can pass its value in a local constant. Having define a structure we can now create a Buffer variable.
The above creates a buffer variable of type TelephoneBook. When a buffer variable is created this way, the correct size of memory is allocated. We can access this memory for read or write using the following syntax:
The dot character is used to separate the field name from the Buffer variable. In an alternative syntax we can merge the structure definition with the declaration of the Buffer variable:
Buffer variables allocate their own memory automatically but this is not the only case. We can declare a buffer variable to point in any valid memory address. For this purpose we use the optional part ADDR in any Buffer variable definition:
or
Where we get AnyMemAdr? AnyMemAdr can be:
The above creates a buffer variable that points to the address of bb.fld of another Buffer variable bb. Character & means "Address of". You can pass there a File variable in exactly the same syntax:
Doing so it is possible to access a file (controlled by the File variable - FileVar in our example) through the Buffer variable and its fields. The whole contents of a Buffer variable can be printed on screen using PrintBuf command. e.g.
This will print:
Additionally Buffer variables can be used to describe API calls: Lets say that there is a DLL math.dll with the following exported C function:
This can be described with the following Buffer variable:
The name we choose for the Buffer variable must be the same with the one of the imported function. To make the API call we use the command APICall:
Using this syntax the call to AddTwoNumber is made, the numbers 100 and 200 are added and the result (300) is returned to the variable sm. For complete information about Buffer variables see "Using Buffer Variables" topic. |
||||||||||
Classes and Class Variables | To create a Class variable we have,
first, to create a Class definition. A Class is created almost the same
way as a UDF. Is a piece of CalcIt code and contains global variables and
local functions. Some of the functions or variables can be declared as public
and this way, through a Class Variable, can be called directly in any
other piece of CalcIt code. Additionally in Class definitions we
can declare public constants.
Multiple inheritance is supported. A Class can inherit any number of other Classes. Class definitions, like UDF are stored in a special list, the Classes list. Every Class has an optional construction and an optional destruction. In construction generally we initialize our global variables. Destruction is useful mainly when a class is used as a wrapper of an API. In such a case, for example in a DATABASE API, we connect in construction and disconnect in destruction. The construction code is actually all the main code if it was a UDF (the code not included in local functions) and the construction parameters are actually the parameters of UDF, if it was a UDF. To have destruction code to be called automatically by CalcIt when the Class variable is destroyed, we just have to include in our Class code a non public local function with the name "Destroy". Every Class variable is an instance of one of the defined Classes in Classes list and has its own private memory for the global variables it contains. Lets say that there is a Class with the name CArray which implements a two dimensional dynamic array. In its construction takes two parameters that define the dimensions of the array. We create an instance of this Class with the following syntax:
The above creates a Class variable ar for the Class definition CArray and calls its construction code to initialize a two dimensioned array 10X2. The Class CArray contains a public function with the name Rows. This function returns the number of rows currently in the array. We can print the number of rows using the following syntax:
Using the dot character we separate the Class variable from the name of the public function we call. Classes and Class variables is a more powerful and versatile way to extend Calcit functionality instead of using "monolithic" UDFs. Their use is important as "Import Classes" to wrap APIs in the most convenient, for the user, interface. For a complete description of Classes and Class variables see "Using Classes and Class Variables" topic. |
||||||||||
Delimited Text | Any kind of text which contains parts separated by a
specific character not used for any other purpose in the text, is a kind
of delimited text. CalcIt can handle efficiently and easily such kind of
text which is very common in text processing. For example consider the
following statement:
Assigns a kind of delimited text to the variable a. We use character | as the separator character. This character is also the default separator character for CalcIt. There are 6 separate parts in this text. We can access any of these parts easily either for read or write. See how:
The first statement changed the third part of the text and replaces the previous value of 'Pentium' with the new variable of 'ZIP drive'. The second statement prints in output window the contents of the third part (now 'ZIP drive'). The third statement print the now changed contents of a, that is:
As we can observe an index kind of syntax is used to access the parts of a delimited text, following symbol #. In case of an array element the following syntax is used:
Assigns in the third position, second delimited part the value 'test'. We can count the number of parts in a delimited text using the PartsCount command. E.g.
Handling delimited text that way the default delimiting character is used. This character is | or chr(124). We can change the default delimiting character with the command DELIMITER. e.g.
The above changes the delimiting character to the space (' ') character. That way any text containing English (or in any other language, of course) can be accessed at a word level. Additionally we can define the delimiting character to be used in a specific command using another optional parameter in the access syntax. E.g.
The
above accesses the second part using comma We can access individual characters in a part of delimited text for read and write using [ ] symbols and an index:
Also, in one statement, we can apply delimited text syntax as many times as needed using different delimiter every time. e.g.
The
second line of the above code returns the value part of any string in the
form <something>value</something>.
The first time the > is used as a delimiter that returns ' NOTES: Parts of delimited text can not be passed in IN/OUT parameters of Local Functions or UDFs. Can be passed normally in IN parameters of any kind. Also PACK and UNPACK commands can be used to handle delimited text. PACK packs the contents of an array in one value of delimited text. UNPACK does the reverse. See more about these commands in the alphabetical list of CalcIt symbols. Delimited text for dynamic arrays (see above) are handled with a second index inside a new consecutive pair of parentheses. Delimited text syntax (and also character access [ ] syntax) can be applied the same way in symbolic constants and function results (Local, Standard or UDF). Of course only for read. See also Text Processing below. |
||||||||||
Text Processing | CalcIt language is very flexible in handling text files and data.
There are many commands to handle text data:
CADJ,DELETE, FIND, INSERT, LADJ, LEFT, LEN, LTRIM, LOCASE, MID, RADJ, REPLACE, RIGHT, RTRIM, TRIM, UPCASE. Not to forget the easy handling of delimited text! Also commands REPLACE and FIND have versions that use powerful regular expression syntax to handle text data: REReplace and REFind. See regular expressions syntax and how these commands can be used in alphabetical keywords list. Plus operator (+) or even better (faster) operator & can be used to concatenate easily text values and create composite strings. We can use all comparison operators
( We can access individual characters in the content of a variable or array element using [ ] symbols and an index:
Using READ and WRITE commands we can read or write a text file in a single step. Text files are always loaded in array variables which makes their processing very easy. See also String formatting below. |
||||||||||
String formatting | Inherent in any expression is the ability
to format easily its result as regards width, justification, fractional digits for
numeric values, the character to be used for the justification and thousands
separation. Consider the following example:
In the second expression after (:) follows a string that defines the formatting to be used. The output of the above statement is:
The part of the statement in bold red
formats All sections in formatting string are optional and can be omitted but the order to put them is specific as below: W.FJNST Where:
TIP: If you want to format data in
width and/or fractional digits then you can omit single quotes in the formatting
string. e.g. NOTE: Formatting string can be the result of an expression. For more string formatting capabilities see also STR, STRF, PRINT, PRINTF. |
||||||||||
Creating and Using Forms: Form variables | With Form variables we can create and
handle data entry forms. To use a Form in our code we have first to define
its layout using the command FORMDef. This command returns an
ID representing a Form layout and we can use it to create running
instances of it.
With the first statement we create a form layout and with the second we create a Form instance based on this layout. The constant 100 is an ID we choose to name the newly created Form instance. Using the variable frm we can handle the Form, access its properties and the properties of controls it contains.
The above statement changes the border of the Form to a single line with no resize capability.
The above assignment statement changes the text of an edit control in frm. The constant MYNAME is the ID we gave to this controls in its definition via the FORMDef command. The user interaction with a Form fires events and the code needs to handle them and take appropriate actions. For example the user presses a button "Calculate" and our code must catch it, make the calculation based in the user input in some edit controls and display it in others suitable for display purposes. To handle events we just have to place in our code a local function with the name EventProc. This function must have a specific parameter interface that passes all the information needed to identify the type of the event and its source so to take the correct action. The interface is the following:
Using the parameters we can distinguish which form fired the event (FrmID), by which control (ConrolID) and what kind this event was (Action). Some events carry additional information and this is the purpose of the Data parameter. Supported events are:
To make a Form visible and start editing we use command ShowForm.
To hide\close a Form we use the command CloseForm.
When our code uses its own Forms maybe is not desirable to have the usual CalcIt windows behind and we can hide them using the command Hide. We can make them visible again using Show. Note that when the code finishes the CalcIt windows become visible automatically. If CalcIt windows is hidden, still we have the ability to see the output of PRINT, PRINTF, PRINTARR redirecting their output to any Memo control on our Forms. We use SetOutput command.
Here is a summary of commands related with Form variables:
In bold are the special commands that define controls in the controls definition list. See more about them at Defining Controls. See a complete description of this feature in Using Form variables topic. Visual Form Designer (VFD) can handle FORMDef creation in behalf of the user who designs his/her Forms interactively in a WYSIWYG editor. Commands CONFIRM and SHOWMESSAGE can benefit Form programming. See also CalcIt executables. |
||||||||||
Printing in color and style (on screen and printer) | Is possible to print a text with sections in various
colors and styles. For this to be possible a form with a
ctrRTFMEMO (Rich Text Format) control is needed
and this control has to be set as default output through SetOutput
command. Then the usual PRINT or PRINTF commands are used
with a... twist!
To those commands, the additional information for the color and style has to be passed. So a multi-field value is used which passes the value to print in one field and the color and style information in others. The Fields are:
The color information can be any RGB color (returned by the RGB command). Also any of the predefined RGB constants (like clRED etc) can be used. The style information is passed through a string value which contains a combination of the letters B, U, S, I. B stands for Bold, U for Underline, S for Strikeout and I for Italic. VCS
command can help to pass easily the additional information. For example
The command
will print something like this:
PRINTF can be used in the following way:
The above will print:
NOTE that ctrMEMO control is faster and consumes much less system resources than ctrRTFMEMO. Of course if only few lines has to be print, there is no much a difference. TOPRINTER command can send the contents of any ctrMEMO or ctrRTFMEMO control, currently selected as output, to the default printer. |
||||||||||
Local Functions | Inside CalcIt code local functions can be defined. These
functions must not confused with User Defined Functions (UDF).
Parameters can be of the following types:
For simple and array type IN parameters default values can be assigned. NOTE: IN parameter passing is what usually call BY VALUE and IN/OUT is what usually call BY REFERENCE. See more in alphabetical list of CalcIt symbols. See also Properties below. |
||||||||||
Properties | A property is a special kind of local
function. Offers a syntactical convenience. Can be described as
"programmatic variable". We can read the value of a property the
same way we can call a local function and get the value it returns BUT we
can write to a property using the assignment operator (:=).
The code of every property has three parts.
Properties can be created in any piece of CalcIt code and are especially useful to Classes. In Classes we can have public properties. See Using Classes and Class variables topic. A property code looks like below:
Where x is a global array. For complete information about properties see Property in Alphabetical list of CalcIt symbols. |
||||||||||
User Defined Functions (UDF) | User Defined functions can be defined to extend easily the
set of available commands in CalcIt. These functions are written with no different
way from any other piece of CalcIt code and customize the CalcIt command set to the
special needs of every user. See more in the specific
topic.
Parameters of UDF can be of the following types:
Array, Automation and Function parameters can be declared through command extern only. Additionally only through extern we can declare IN/OUT parameters when this is permitted. Default values can be assigned to simple type parameters through extern command. Simple variables of the code become automatically parameters when the code tries to read their value before any assignment operation to them. This way the parameters are always IN. |
||||||||||
Loops | Loop commands fully supported in CalcIt language. FOR, WHILE, REPEAT. See alphabetical list. | ||||||||||
Program Flow control | IF...ELSE...END and SELECT...CASE...ELSE...END constructs can be used. | ||||||||||
Clipboard | We can exchange data easily with clipboard. See CLIPREAD and CLIPWRITE commands in alphabetical list. | ||||||||||
Operators | CalcIt supports many operators for numeric, alphanumeric or logical processing. For the logical operators AND and OR Short Circuit Boolean evaluation is supported. See more in the specific topic. | ||||||||||
Date handling | There are commands to support date data. Dates can be
represented by a number which can be processed as any number. Also there
are commands to switch from numeric to human readable format and reverse.
See commands DATE, DAY,
MONTH, YEAR,
TODAY, DATESTR,
WEEKDAY, STRDATE,
VALIDDATE
Date constants can be inserted directly in the code. See CalcIt constants. TODAY function returns the system date in various convenient formats in a multi-field value. |
||||||||||
TIME | Use TIME command to get the current system time | ||||||||||
Directory Handling | Commands to handle files on disk. See commands READDIR,
CURDIR, DELFILE,
RENFILE, GETFILE,
GETPATH, FILEEXISTS,
MAKEDIR, COPYFILE,
DIREXISTS.
Command READDIR loads the contents of a directory in an array variable in a single step. |
||||||||||
Text Output | Commands PRINT, PRINTF, CLEAR and MSG/DESCR can be used to write text in special output windows. | ||||||||||
Debugger | See specific topic of how we can debug CalcIt code with a full featured source level debugger. | ||||||||||
Trigonometric functions | SIN, COS, TAN, ARCSIN, ARCCOS, ARCTAN. Also we can select between DEGREES, RADIANS or GRADIENTS using ANGLESUNIT command. | ||||||||||
Hyperbolic functions | SINH, COSH, TANH | ||||||||||
Numerical, Statistical | ABS, FRAC, INT, ROUND, SQRT, MIN, MAX, AVRG, SUM | ||||||||||
Random number generation | RANDG, RANDOM functions, RANDOMIZE command and RANDSEED system parameter. | ||||||||||
Constants | There are many and powerful ways to define constants in CalcIt. Also there is a number of predefined constants. Additionally the user is able to create his/her own symbolic constants in Constants list. Also we can declare symbolic constants local in a code using the command CONST. | ||||||||||
Commands to handle Calculation Items | The commands below handle Calculation items in the Calculations list (Calculating part) |