# Math based script

Go to solution Solved by Subz,

## Recommended Posts

Hi everyone,

I'm terribly sorry if this is not the place to ask for this question, but I'm poor at developing scripts so I'm asking for your help or guidance.

I want to make a script where I enter a number and it automatically calculates it into the answer.

If I were using excel the formula would be "=(A1/(1-5,5%))*(1+20%)", and it would probably be easy to figure out a way to make a .exe or something from it running through excel, but I'll mostly be running this on a computer without the office package installed(only 365).

What I have in mind is a small window where I write the number that would be in cell A1, let's say 100 - and a new window would pop up and show 126,98(two decimals required).

I wonder if this is even possible at all, I guess it'd require huge .txt files with numbers to even make sense. I'm very new - point blanc.

Thank you, and my deepest apologies if this is the wrong place to ask or if it's an "impossible" task.

##### Share on other sites
• Solution

Maybe something like:

```#include <GUIConstantsEx.au3>

Global \$g_iInput, \$g_idInput, \$g_idOutput
_Example()

Func _Example()
GUICreate("Calculate", 110, 90)
\$g_idInput = GUICtrlCreateInput("", 5, 5, 100, 20)
\$g_idOutput = GUICtrlCreateInput("", 5, 30, 100, 20)
GUICtrlSetState(\$g_idOutput, \$GUI_DISABLE)
Local \$idOutput = GUICtrlCreateButton("Copy to Clipboard", 5, 55, 100, 30)
GUISetState()
While 1
Switch GUIGetMsg()
Case \$GUI_EVENT_CLOSE
ExitLoop
Case \$idOutput
EndSwitch
WEnd
EndFunc

Func _Calculate()
If \$iInput = \$g_iInput Then Return
Local \$sCalculate = Round((\$iInput/(1-5.5/100))*(1+20/100), 2)
GUICtrlSetData(\$g_idOutput, \$sCalculate)
\$g_iInput = \$iInput
EndFunc```

##### Share on other sites

That is perfect Subz, I've tried so hard on my own. But without knowledge of anything it has been a struggle

Thank you so much!

##### Share on other sites

Streamlined (I guess more correct) calculation:

`Local \$sCalculate = Round(\$iInput * 0.945 * 1.2, 2)`

Substracting 5.5% is equivalent to multiplying by: (100 - 5.5) / 100 which is 0.945

Adding 20% is equivalent to multiplying by: (100 + 20) / 100 which is 1.2

You divide by 0.945, so you end up adding around 5.82% which I guess isn't what you want: 100 / 0.945 = 105.820105820106

With input 100 the (I guess correct) result is: 113.40

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...