ToyCalculator

Post your working scripts, libraries and tools for AHK v1.1 and older
lyubarsky
Posts: 9
Joined: 01 Mar 2023, 13:09

ToyCalculator

06 May 2024, 12:01

ToyCalculator
-------------------------------------------------------------------------------

Source: https://www.dropbox.com/scl/fi/5m299isrr5jpir443mxca/ToyCalculator.en.zip?rlkey=a6x1fkxmqx73dtnruyludc2e7&st=y6mh4itv&dl=1
Compiled exe-file: https://www.dropbox.com/scl/fi/sg35puhar45mfd6022nwy/ToyCalculator.en.exe?rlkey=0e3s6z25425cl0jw8b7bixis1&st=ndu7e6jr&dl=1

In a simple usage, ToyCalculator uses Dijkstra's algorithm to calculate several mathematical expressions, perhaps related to each other by user variables. Moreover, to use the calculator, you only need to know the designations of arithmetic operators (, -, *, /, //, **) and the symbols of the assignment operator (=), and comments (;). Where mathematical expressions are written and where the results of calculations are displayed can be understood from the following example. It, like all other examples, can be copied into the calculator window and run. Counting begins by pressing the Start button or the keyboard shortcut F5.

A simple example.
Spoiler

You can also use regular mathematical functions of one or more variables, such as sin(), cos(), min(), and so on. All these functions for typing speed are placed in the Functions drop-down list.

In general, the ToyCalculator syntax, with the following exceptions, is the same as the AutoHotkey syntax. It's easiest to look at the examples below. In addition, the calculator finds the most common syntax errors and displays messages about them.

Using the standard File menu, you can save the typed formulas in text format and use them repeatedly in the future.

Example 2. Calculation of loan payments and its cost.
Spoiler
Note 1 (for beginners). A mathematical expression that includes user variables must come after the definition of those variables.

More complex mathematical calculations may involve loops and branching constructs. There are two loops: While and Until, and one branching construct If-Elseif-Else. The If block is required, but the Elseif blocks, of which there may be several, and the Else block may be absent. There can be several cycles, as well as branches, and they can be nested within each other to any depth.

Note 2. All logical conditions in loops and branch structures must be enclosed in parentheses. Block curly braces are required even when the block consists of a single statement. (In branching structures, you can limit yourself to the first and last parenthesis, but then the calculator will not automatically indent.)

You can use the Break() and Continue() utility functions in loops. They are no different from ordinary similar operators except that their arguments are logical expressions, if true they are triggered. This is justified by the fact that Break and Continue typically follow conditional statements.

Similarly, the Stop() function stops the loop when the condition in its argument is true. After examining the values of the variables, the counting can be continued by clicking the Start button, or completed completely by clicking the Stop button. The function is intended for debugging.

You can monitor what happens during the execution of a loop, that is, what values variables and expressions take during the calculation process, using the Collect() function. The parameters of this function are variables or expressions. The Collect() function collects sequential values of each parameter during the counting process and writes it to a CSV file after counting ends or stops. This file immediately opens in MS Notepad. In addition, the CSV file can be imported, for example, into MS Excel and the necessary graphs can be built.

Note 3. There should be only one Collect() function, preferably placing it at the end of the loop body. This function can have any number of parameters.

The cycle can be stopped at any time with the Stop button and continued with the Start button. Pressing the Stop button again will complete the calculation.

Example 2. While loop.
Spoiler
Example 3. Until loop.
Spoiler
Example 4. Branching.
Spoiler
Example 5. Coin game.
Spoiler
Пример 6. Тест Laszlo.
Spoiler
If you want to have a faster calculator that immediately draws beautiful graphs using the HTML5 canvasJS library, then you are welcome to visit my website https://blackboard.su

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 54 guests