All calculations are automatically formatted and collected into a professional looking calculation report. You can print it or open with Word for editing. Besides math expressions, you can add headings, comments, tables and images.
A heading is a text, enclosed in double quotes ("). It is bold and larger than the other text and is normally used for titles.
Comments are enclosed in single quotes ('). You can skip the closing quote, if it is the last symbol on the line. Headings and comments can contain any symbols without restrictions. Everything outside is assumed to be math expressions. However, if any expressions are put inside comments, they will be left "as is": they will not be calculated and formatted. Since the final output is rendered to an Html document, you can use Html and CSS inside comments and apply additional formatting to your calculation report.
Alternatively, you can enter all values as unitless and write the units in the comments. In this case, you have to include all unit conversion factors into the equations. Also, there is an option to generate a selection box for length units - m, cm and mm. It is only required to insert %u in comments wherever you want units to appear. When the program generates an input form (see further) it checks whether %u exists somewhere in the script. If so, it automatically adds a combo box for selection of units at the top-right corner of the form. When you change the units from the combo, they are filled at all occurrences of %u in the script. You can try it bellow:
'Length - ' l = ? '%u
'Area - ' l = ? '%u<sup>2</sup>
'Volume - ' l = ? '%u<sup>3</sup>
'Scale factor - 'Units
Length - l = m
Area - l = m2
Volume - l = m3
Scale factor - Units
When you run the calculations, the units combo disappears and all units remain in the output as filled. The program also creates an automated variable Units, which contains the factor to convert the selected units to meters. Its value is 1, 100 and 1000 for m, mm and cm, respectively. You can use it for units conversion inside the calculations. For example, you can create a conditional block for displaying the selected units in the report:
#if Units ≡ 1
'The selected units are meters
#else if Units ≡ 100
'The selected units are centimeters
#else if Units ≡ 1000
'The selected units are millimeters
Calcpad can be used as a platform to develop professional engineering programs. If you are not going to do that, you can skip this chapter.
Html (Hyper Text Markup Language) is a markup language which is created for formatting web pages. You can change font type, size, weight or color, insert tables, images, etc. This is performed by adding special elements called "tags". Each tag is enclosed in angular brackets: "<tag>". Some tags are used in pairs - opening "<tag>" and closing "</tag>". The contents is going in between. For example, if you want to make some text bold, you need to use the following tags: <b>Bold text</b>. Even if you are not a professional programmer, you can easily learn some basic Html, to use with Calcpad:
|<span style="font:16pt Times-New-Roman;">Times New Roman, 16pt</span>||Times New Roman, 16pt|
You can put Html tags only in comments, but you can also make them to apply to expressions. For example:
'<span style="color:red;"> as simple as ' 2 + 2 '</span>'
will provide the following output:
as simple as 2 + 2 = 4
What we have here are two comments and expression in between. The first comment contains the opening tag '<span style="color:red;">' and the second - the closing tag '</span>'. Everything between the two tags is colored in red. Make sure you do not forget the quotes. Otherwise, the program will try to parse the Html code as math expression and will return an error. The following code: style="color:red" is not really Html, but a very useful extension, called CSS (Cascading Style Sheets). It is used to format the look of Html documents. You can learn more about Html and CSS from the following links:
You can also use some of the many free WYSIWYG Html editors that you can find on the Internet.
before inserting an image to a Calcpad document, you need to have it as a ready made file. You can create it by some image editing software and save it as a *.png, *.gif or *.jpg file. You can use freeware programs like Paint, Gimp, InkScape, DraftSight or others. Then you can insert it using Html. All you need to do is to put the following text at the required place, inside a comment:
'<img style="float:right" src="c:\Users\Me\Pictures\Picture1.png" alt="Picture1.png">'
Of course, instead of "c:\Users\Me\Pictures\Picture1.png" you have to specify the path to your actual image. The text style="float:right" aligns the image to the right allowing the text to float at the left side. Otherwise, the image will become part of the text flow and will make it split. Sometimes, you may have a larger image, with no place for the text to flow around. In this case, you can skip the "float:right" style.
You can also insert an image using the button from the toolbar. You will be prompted to select a file. When you click "Open", the required record will be inserted at the beginning of the script. When you run the calculations, the picture will appear in the output window.
It is very common that a solution should continue in different ways, depending on some intermediate values. Calcpad includes a powerful solution, similar to other programming languages. It is called "conditional execution block". It has the following general form:
Shorter forms are also possible:
You can use it not only to split the calculation path, but also to show different content like text and images. The symbol "#" must be the first in the line. At the place of "condition" you can put any valid expression. Normally, a comparison is used like "#If a < 0", but it is not obligatory. If the result is nonzero, the condition is assumed to be satisfied. If it is zero - not satisfied. Any result which absolute value is ≤ 0.00000001 is assumed to be zero.
Let us look again at the quadratic equation example that we used earlier. If we enter "c = 5", the discriminant will be negative and the result will be NaN. This is not a very intelligent way to finish. What we need to do is to check if "D < 0" and if so, to provide a comprehensible message. Otherwise, we have to calculate the roots. We can do this, using conditional execution as follows:
They help us to control which parts of the script should be visible in the output. Unlike conditional execution, the hidden code is always calculated but not displayed. The following commands are included:
Each of the above commands affect the contents after the current line and overrides the previous one. You can use them to hide long and repetitive calculations that do not have to be visible. You can use the #Pre command to add some directions about filling the input data and #Post to hide the calculation algorithm during data input.
You can also modify the rendering of the calculations as follows:
Each of the above commands overrides the other one. You can use #Val to create a table with values only, by hiding the formulas like in Excel.
You can use simple iterations inside Calcpad. For that purpose, you have to define a "repeat-loop" block:
The symbol n stands for the number of repetitions. Instead of n, you can put a number, variable and any valid expression. If the result of this expression is not integer, it is rounded to the nearest one. You can exit the repeat-loop cycle prematurely by putting #Break somewhere inside the block. It is also recommended to add a condition to be satisfied before you break. Otherwise, it will always break the first time, without performing any loops. A typical "repeat-break-loop" will look like this:
You can omit the number of repetitions n only if you are sure that the condition will be satisfied and the loop will brake sooner or later. Anyway, to avoid infinite loop, the number of iterations is limited to 100 000 if nothing else is specified.
You can use loops either to generate repetitive output (like tables) or to perform iterative calculations in the background. If you want to hide the iteration details, you can use output control directives (see the previous section). For example, you can enclose the "repeat-loop" block with #Hide and #Show statements.
If you have a long and complex problem with a lot of parameters to change or you want to share your solution with others, it is a good idea to create an input form. This is very easy to do with Calcpad. Just replace the values that need to be entered with question marks "?", e.g. "a = ?". After that, you will not be able to calculate the script directly with the button. First you must compile it to an input form, using the button.
The problem is loaded into the "Input" box at full width of the main window. All text and formulas are rendered and formatted to Html and cannot be modified. Input boxes are generated at every occurrence of the "?" symbol except those in comments. The form is ready to use and looks like follows:
Now you have to fill the input boxes and click to calculate the results. They are displayed in the "Output" box.
In order to return to input mode, click again to switch off the button. Data in input boxes remains unchanged since the last input. If you need to modify the source code, you have to unlock it with the button. The "Script" box is displayed again in the left half of the main window. When you finish, you can compile the input form again, but the last input data will be cleared. Finally, you can save the document as a "*.cpd" file. When you open such file, it is displayed directly in input form mode. It is more convenient to use than a simple text file due to the following advantages:
If you save the document as a "*.cpdz" file, the source code will be no longer accessible. You will not be able to unlock the source code inside Calcpad. Also, it will not be possible to edit the file in external text editor, because it will be encoded. That is how you can protect your source code from coping, viewing and modification.
You can put the question mark "?" not only in variable definitions, but at any place in the code:
2 + ?
When you compile it to form, an input box will be generated at the place of the question mark:
You can enter a value and calculate the result. This approach is not recommended for complex problems, because the logical structure gets unclear and difficult to understand.