Jump to content

Creating a custom formula calculator


Recommended Posts

Hello there,

I was wondering if it's possible to create some kind of calculator with custom formulas...

I'm dutch and I often use my own letters in formula's, since I only have very basic physics almost all formulas look the same.

This is an example:

A=B*C

C=A/B

B=A/C

Now would I be able to create a calculator for this? That calculates the A if I fill in B and C?

Thanks a lot,

Chris

Link to comment
Share on other sites

The short answer to your question is:

Yes!

The long and slightly more complex answer is:

Yes, you would be able to do this if you are willing to do a bit of reading and put a bit of effort into it.

Edited by Bomi
Link to comment
Share on other sites

I am not sure what level of complexity you were looking for but I came up with this.

1. Fill in the constants with alphabet characters and their associated equation.

2. Enter the equation you want to compute using the constants you entered.

A = 1

B = 2

C = 3

Equation = A+B+C

Effective equation = 1+2+3

Result = 6

#include <GUIConstants.au3>

GUICreate("My GUI", 400, 480)  ; will create a dialog box that when displayed is centered
GUISetState (@SW_SHOW)       ; will display an empty dialog box

GuiCtrlCreateLabel("Constant", 10,10)
GuiCtrlCreateLabel("Formula", 200,10)

Dim $array[10][2]

For $Y = 0 to 9
    $array[$Y][0] = GuiCtrlCreateInput("", 20,($Y * 25)+30,20,20)
    $array[$Y][1] = GuiCtrlCreateInput("", 70,($Y * 25)+30,320,20)
Next

GuiCtrlCreateLabel("Equation", 10,300)
$equationInput = GuiCtrlCreateInput("", 10,320,380,20)

GuiCtrlCreateLabel("Effective Equation", 10,350)
$effectiveInput = GuiCtrlCreateInput("", 10,370,380,20)

GuiCtrlCreateLabel("Answer", 10,400)
$answerInput = GuiCtrlCreateInput("", 10,420,380,20)

$button = GuiCtrlCreateButton("Calculate", 170, 450, 60, 20)

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()  
    
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $button
            Calculate()
    EndSwitch
Wend

Func Calculate()
    $final = GuiCtrlRead($equationInput)
    
    For $Y = 0 to 9
        $constant = GuiCtrlRead($array[$Y][0])
        $formula = GuiCtrlRead($array[$Y][1])
        
        If IsString($constant) and StringLen($constant) > 0 Then
        $final = StringReplace($final, $constant,$formula)
        EndIf
    Next
    GuiCtrlSetData($effectiveInput, $final)    
    GuiCtrlSetData($answerInput, Execute($final))    
EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...