Jump to content

expression evaluation


DaveB
 Share

Recommended Posts

New Update. Including bug fixes and documentation as comments. Also a trouble shooting window at the very bottom of window which shows the Input string just before it is "executed"

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\Icons\au3.ico
#AutoIt3Wrapper_Outfile=..\..\..\Documents and Settings\Dave1\Desktop\evaluate it.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $a, $b, $C, $d, $e, $f, $g, $h, $i, $j, $k, $l, $m, $n, $X, $Y, $Z, $Input1, $b1, $Input4, $input5
Global $TroubleShoot
#Region ### START Koda GUI section ### Form=
Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("Evaluate the Expression", 533, 450, 192, 114, $WS_EX_DLGMODALFRAME)
GUISetBkColor(0xA6CAF0)

$Label100 = GUICtrlCreateLabel("Answer:", 180, 16, 88, 28)
GUICtrlSetFont(-1, 12, 800, 0, "Georgia")

$Label200 = GUICtrlCreateLabel("Enter Expression Here", 112, 100, 244, 27)
GUICtrlSetFont(-1, 12, 800, 0, "Century")

;COLUM 1 ...............................................................................

$Input1 = GUICtrlCreateInput("", 72, 160, 106, 20) ; $A
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

$Input2 = GUICtrlCreateInput("", 72, 181, 106, 20) ; $d
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

$Input3 = GUICtrlCreateInput("", 72, 202, 106, 20) ; $g
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

$Input4 = GUICtrlCreateInput("", 72, 223, 106, 20) ; $j
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

$input5 = GUICtrlCreateInput("", 72, 244, 106, 20) ; $m
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

$Input6 = GUICtrlCreateInput("", 72, 265, 106, 20) ; $p
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

$Input7 = GUICtrlCreateInput("", 72, 286, 106, 20) ; $s
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

$Input8 = GUICtrlCreateInput("", 72, 307, 106, 20) ; $v
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

$Input9 = GUICtrlCreateInput("", 72, 328, 106, 24) ;$y
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

$Label1 = GUICtrlCreateLabel("A =", 32, 160, 34, 28)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Label2 = GUICtrlCreateLabel("D =", 32, 181, 34, 28)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Label3 = GUICtrlCreateLabel("G =", 32, 202, 34, 28)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Label4 = GUICtrlCreateLabel("J =", 32, 223, 34, 28)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Label5 = GUICtrlCreateLabel("M =", 32, 244, 34, 28)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Label6 = GUICtrlCreateLabel("P =", 32, 265, 34, 28)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Label7 = GUICtrlCreateLabel("S =", 32, 286, 34, 28)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Label8 = GUICtrlCreateLabel("V =", 32, 307, 34, 28)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Label9 = GUICtrlCreateLabel("Y =", 32, 330, 29, 20)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

;colum 2..................................................................................

$Label10 = GUICtrlCreateLabel("B =", 192, 160, 34, 28)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Label11 = GUICtrlCreateLabel("E =", 192, 181, 34, 28)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Label12 = GUICtrlCreateLabel("H =", 192, 202, 34, 28)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Label13 = GUICtrlCreateLabel("K =", 192, 223, 34, 28)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Label14 = GUICtrlCreateLabel("N =", 192, 244, 34, 28)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Label15 = GUICtrlCreateLabel("Q =", 192, 265, 34, 28)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Label16 = GUICtrlCreateLabel("T =", 192, 286, 34, 28)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Label17 = GUICtrlCreateLabel("W =", 192, 307, 34, 28)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Label18 = GUICtrlCreateLabel("Z =", 192, 328, 29, 20)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Input10 = GUICtrlCreateInput("", 232, 160, 106, 20) ; $B
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

$Input11 = GUICtrlCreateInput("", 232, 181, 106, 20) ; $E
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

$Input12 = GUICtrlCreateInput("", 232, 202, 106, 20) ; $H
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

$Input13 = GUICtrlCreateInput("", 232, 223, 106, 20) ; $K
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

$Input14 = GUICtrlCreateInput("", 232, 244, 106, 20) ; $N
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

$Input15 = GUICtrlCreateInput("", 232, 265, 106, 20) ; $Q
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

$Input16 = GUICtrlCreateInput("", 232, 286, 106, 20) ; $T
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

$Input17 = GUICtrlCreateInput("", 232, 307, 106, 20) ; $W
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

$Input18 = GUICtrlCreateInput("", 232, 328, 106, 24) ;$Z
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

;colum 3  ...............................................................................

$Label19 = GUICtrlCreateLabel("C =", 344, 160, 34, 28)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Labe20 = GUICtrlCreateLabel("F =", 344, 181, 34, 28)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Label21 = GUICtrlCreateLabel("I =", 344, 202, 34, 28)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Label22 = GUICtrlCreateLabel("L =", 344, 223, 34, 28)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Label23 = GUICtrlCreateLabel("O =", 344, 244, 34, 28)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Label24 = GUICtrlCreateLabel("R =", 344, 265, 34, 28)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Label25 = GUICtrlCreateLabel("U =", 344, 286, 34, 28)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Label26 = GUICtrlCreateLabel("X =", 344, 307, 34, 28)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Label27 = GUICtrlCreateLabel(": =", 344, 328, 34, 28)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")

$Input19 = GUICtrlCreateInput("", 384, 160, 106, 20) ;$C
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

$Input20 = GUICtrlCreateInput("", 384, 181, 106, 20) ; $F
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

$Input21 = GUICtrlCreateInput("", 384, 202, 106, 20) ; $I
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

$Input22 = GUICtrlCreateInput("", 384, 223, 106, 20) ; $L
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

$Input23 = GUICtrlCreateInput("", 384, 244, 106, 20) ; $O
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

$Input24 = GUICtrlCreateInput("", 384, 265, 106, 20) ; $R
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

$Input25 = GUICtrlCreateInput("", 384, 286, 106, 20) ; $U
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

$Input26 = GUICtrlCreateInput("", 384, 307, 106, 20) ; $X
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")

$Input27 = GUICtrlCreateInput("", 384, 328, 106, 24) ;$:
GUICtrlSetFont(-1, 7, 800, 0, "Arial Black")


$Output = GUICtrlCreateInput(Execute($b1), 50, 48, 430, 45, 0, $WS_EX_DLGMODALFRAME)
GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")
GUICtrlSetBkColor(-1, 0xFFe30)

$Input100 = GUICtrlCreateInput("", 10, 125, 500, 28)
GUICtrlSetFont(-1, 10, 800, 0, "Arial Black")

$TroubleShoot = GUICtrlCreateInput($b1, 10, 375, 500, 28)
GUICtrlSetFont(-1, 10, 800, 0, "Arial Black")

GUISetState(@SW_SHOW)

;@@@@@@@@@@@@@@@@@@@@@@ START/STOP @@@@@@@@@@@@@@@@@@@@@@@
HotKeySet("{ESC}", "Terminate") ; TERMINATE THE RUN
HotKeySet("{Enter}", "Main") ; RUN MAIN PROGRAM
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate


#EndRegion ### END Koda GUI section ###
While 1
    Sleep(100)
WEnd

Func Main()
    $b1 = GUICtrlRead($Input100) ;read unformated input

    ;#######################################################
    $b1 = StringReplace($b1, " ", "") ;remove all spaces
    ;#######################################################

    ;************** FROM HERE DOWN ( FORMATE ) THE INPUT *************
    $b1 = StringReplace($b1, "a", "$a")
    $b1 = StringReplace($b1, "b", "$b")
    $b1 = StringReplace($b1, "c", "$c")
    $b1 = StringReplace($b1, "d", "$d")
    $b1 = StringReplace($b1, "e", "$e")
    $b1 = StringReplace($b1, "f", "$f")
    $b1 = StringReplace($b1, "g", "$g")
    $b1 = StringReplace($b1, "h", "$h")
    $b1 = StringReplace($b1, "i", "$i")
    $b1 = StringReplace($b1, "j", "$j")
    $b1 = StringReplace($b1, "k", "$k")
    $b1 = StringReplace($b1, "l", "$l")
    $b1 = StringReplace($b1, "m", "$m")
    $b1 = StringReplace($b1, "n", "$n")
    $b1 = StringReplace($b1, "o", "$o")
    $b1 = StringReplace($b1, "p", "$p")
    $b1 = StringReplace($b1, "q", "$q")
    $b1 = StringReplace($b1, "r", "$r")
    $b1 = StringReplace($b1, "s", "$s")
    $b1 = StringReplace($b1, "t", "$t")
    $b1 = StringReplace($b1, "u", "$u")
    $b1 = StringReplace($b1, "v", "$v")
    $b1 = StringReplace($b1, "w", "$w")
    $b1 = StringReplace($b1, "x", "$x")
    $b1 = StringReplace($b1, "y", "$y")
    $b1 = StringReplace($b1, "z", "$z")
    ;#######################################################
    $b1 = StringReplace($b1, "(", "*(") ;correct for ")("
    $b1 = StringReplace($b1, "+*", "+") ;correct for "+("
    $b1 = StringReplace($b1, "-*", "-") ;correct for "-("
    $b1 = StringReplace($b1, "/*", "/") ;correct for "/("
    $b1 = StringReplace($b1, "^*", "^") ;correct for "^("

    ;$b1 = StringReplace($b1, "$", "*$") ;correct for ")("
    ;$b1 = StringReplace($b1, "+*", "+") ;correct for "+("
    ;$b1 = StringReplace($b1, "-*", "-") ;correct for "-("
    ;$b1 = StringReplace($b1, "/*", "/") ;correct for "/("
    ;$b1 = StringReplace($b1, "^*", "^") ;correct for "^("


    ;*****************CORRECT FOR MULIPLE LEADING PARENTHS*****
    $b1 = StringReplace($b1, "(*(", "((")
    $b1 = StringReplace($b1, "((*(", "(((")
    $b1 = StringReplace($b1, "(((*(", "((((")
    ;**********************************************************

    ;#######################################################
    $b1 = " " & $b1 ;insure that there will always be one space as the first character
    ;#######################################################
    $b1 = StringReplace($b1, " *", " ") ;since spaces are removed then correct for "(" as first chr
    $b1 = StringReplace($b1, "**", "*")
    $b1 = StringReplace($b1, "$t$a$n", "tan")
    $b1 = StringReplace($b1, "$c$o$s", "cos")
    $b1 = StringReplace($b1, "$e$x$p", "exp")
    $b1 = StringReplace($b1, "$s$i$n", "sin")
    $b1 = StringReplace($b1, "$asin", "asin")
    $b1 = StringReplace($b1, "$a$b$s", "abs")
    $b1 = StringReplace($b1, "$acos", "acos")
    $b1 = StringReplace($b1, "$atan", "atan")
    $b1 = StringReplace($b1, "$l$o$g", "log")


    ;If $b1 = "END" Then
    ;Exit
    ;ElseIf $b1 = "CLR" Then
    ;$Output = ""
    ;EndIf

    $a = GUICtrlRead($Input1)
    $b = GUICtrlRead($Input10)
    $C = GUICtrlRead($Input19)
    $d = GUICtrlRead($Input2)
    $e = GUICtrlRead($Input11)
    $f = GUICtrlRead($Input20)
    $g = GUICtrlRead($Input3)
    $h = GUICtrlRead($Input12)
    $i = GUICtrlRead($Input21)
    $j = GUICtrlRead($Input4)
    $k = GUICtrlRead($Input13)
    $l = GUICtrlRead($Input22)
    $m = GUICtrlRead($input5)
    $n = GUICtrlRead($Input14)
    $o = GUICtrlRead($Input23)
    $p = GUICtrlRead($Input6)
    $q = GUICtrlRead($Input15)
    $r = GUICtrlRead($Input24)
    $s = GUICtrlRead($Input7)
    $t = GUICtrlRead($Input16)
    $u = GUICtrlRead($Input25)
    $v = GUICtrlRead($Input8)
    $w = GUICtrlRead($Input17)
    $X = GUICtrlRead($Input26)
    $Y = GUICtrlRead($Input9)
    $Z = GUICtrlRead($Input18)

    $Output = GUICtrlCreateInput(Execute($b1), 50, 48, 430, 45, 0, $WS_EX_DLGMODALFRAME)
    GUICtrlSetFont(-1, 18, 900, 0, "Arial Black")
    GUICtrlSetBkColor(-1, 0xFFe30)
    ;------------------- TROUBLE SHOOTING WINDOW -------------------
    $TroubleShoot = GUICtrlCreateInput($b1, 10, 375, 500, 28)
    GUICtrlSetFont(-1, 8, 800, 0, "Arial Black")
    ;---------------------------------------------------------------
EndFunc   ;==>Main

post-38053-0-16858300-1305142898_thumb.g

Edited by DaveB
Link to comment
Share on other sites

Nice. If you want to extend this more, I would advise you to lookup the Shunting Yard algorithm to see how this function works behind the scenes, then implement it in pure autoit.

ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search

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...