Guest Posted March 6, 2012 Share Posted March 6, 2012 I have not been doing much recently so i thought i should play around with variables a bit and do some math Maths.au3 $1 = InputBox("Maths", "Number:", "") $operation = InputBox("Maths", "+, -, *:", "") $2 = InputBox("Maths", "plus Number:", "") $plus = $1 + $2 $minus = $1 - $2 $times = $1 * $2 If $operation = "+" Then MsgBox("", "Maths", "= " & $plus) EndIf If $operation = "-" Then MsgBox("", "Maths", "= " & $minus) EndIf If $operation = "*" Then MsgBox("", "Maths", "= " & $times) EndIfMaths.au3 Link to comment Share on other sites More sharing options...
Mat Posted March 6, 2012 Share Posted March 6, 2012 There are a couple of ways to make a calculator that accepts more inputs, like typing "5*3" into one InputBox. The easiest by far is to use the Execute function. Take a look, see what you come up with Then look at GUIs as well and you'll be well on your way to making a fully functional calculator. AutoIt Project Listing Link to comment Share on other sites More sharing options...
AZJIO Posted March 7, 2012 Share Posted March 7, 2012 Calculator on a single line My other projects or all Link to comment Share on other sites More sharing options...
Guest Posted March 7, 2012 Share Posted March 7, 2012 (edited) Thanks this is so much better $input = InputBox("Maths", "Enter an equasion", "") $ans = Execute($input) MsgBox("", "Maths", "Answer = " & $ans) As you said-GUI... I will just get started! Edited March 7, 2012 by Guest Link to comment Share on other sites More sharing options...
JohnOne Posted March 7, 2012 Share Posted March 7, 2012 Indeed, you should consider at least a StringRegExReplace() to remove anything but the maths symbols and digits you want to allow. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Guest Posted March 8, 2012 Share Posted March 8, 2012 OK i am working on that but in the mean time here is a gui! #include <GUIConstantsEx.au3> Local $file, $btn, $msg GUICreate(" Calculator", 395, 30, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES $file = GUICtrlCreateInput("", 10, 5, 300, 20) GUICtrlSetState(-1, $GUI_DROPACCEPTED) $btn = GUICtrlCreateButton("=", 325, 5, 60, 20) GUISetState() $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $btn ExitLoop EndSelect WEnd $ans = execute(guictrlread($file)) MsgBox(4096, "Calculator", $ans) Have fun! Link to comment Share on other sites More sharing options...
JohnOne Posted March 8, 2012 Share Posted March 8, 2012 Don't know how much fun I can have with a calculator, but thanks anyway. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
rcmaehl Posted March 9, 2012 Share Posted March 9, 2012 But will it blend? Haha, no. Secondly, I improved your script a bit. #include <GUIConstantsEx.au3> Main() Func Main() Local $file, $btn, $msg GUICreate("Calculator", 395, 30, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES $file = GUICtrlCreateInput("", 10, 5, 300, 20) GUICtrlSetState(-1, $GUI_DROPACCEPTED) $btn = GUICtrlCreateButton("=", 325, 5, 60, 20) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit (0) Case $msg = $btn GUICtrlSetData($file, Execute(GUICtrlRead($file))) Case Else ;;; EndSelect WEnd EndFunc ;==>Main My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.My Projects WhyNotWin11Cisco Finesse, Github, IRC UDF, WindowEx UDF Link to comment Share on other sites More sharing options...
Guest Posted March 10, 2012 Share Posted March 10, 2012 Wow that's great! Link to comment Share on other sites More sharing options...
Mat Posted March 10, 2012 Share Posted March 10, 2012 (edited) I actually keep a list of calculators: http://code.google.com/p/m-a-t/wiki/Maths#Calculators Edited March 10, 2012 by Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
lorenkinzel Posted April 10, 2012 Share Posted April 10, 2012 (edited) I couldn't resist playing this one out a little farther. This version works nicely (so did the first one). Note that all of the code is like Lego blocks written by others. I just snapped the blocks together. expandcollapse popup#include <WindowsConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <Misc.au3> Global $btn Global $file Global $pi = 4 * ATan(1) Global $degrees = 180/$pi _ReduceMemory() Main() Func Main() Local $file, $btn, $msg $gui = GUICreate("calc U lizer", 395, 35, @DesktopWidth -410, (@DesktopHeight *.925)-40, -1, $WS_EX_TOPMOST) GUISetBkColor(0x000000) $file = GUICtrlCreateInput("", 10, 5, 300, 25) GUICtrlSetFont($file, 12, 400, 0, "MS Sans Serif") GUICtrlSetColor($file, 0xFFFFFF) GUICtrlSetBkColor($file, 0x000000) GUICtrlSetState(-1, $GUI_DROPACCEPTED) $btn = GUICtrlCreateButton("=", 315, 1, 30, 20) GUICtrlSetTip($btn, "enter key") $restart = GUICtrlCreateButton("reset", 350, 1, 35, 20) GUICtrlSetTip($restart, "del key") $qButton = GUICtrlCreateButton("", 315, 23, 30, 11) GUICtrlSetBkColor($qButton, 0xbb21ee) GUICtrlSetTip($qButton, "WTF?") Global $acceleartors[2][2] = [["{ENTER}", $btn], ["{DELETE}", $restart]] ;<<<<<<<<<<<<< GUISetAccelerators($acceleartors, $gui) ;<<<<<<<<<<<<< GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit (0) Case $msg = $btn GUICtrlSetData($file, Execute(GUICtrlRead($file))) Case $msg = $restart _restart() Case $msg = $qButton MsgBox(0, "examples", "exponent-N(squared)....N^2" & @CRLF & "" & @CRLF &"PI....pi()....pi()*2" & @CRLF & "" & @CRLF & "Degrees(57.259etc)....2*degrees()" & @CRLF & "" & @CRLF & "google() <enter> <enter> opens iexplore to google page") ;& no, I have not figured out proper use of the underscore yet EndSelect WEnd EndFunc ;==>Main Func ans() GUICtrlSetData($file, Execute(GUICtrlRead($file))) EndFunc ;==>ans Func _restart() Local $sAutoIt_File = @TempDir & "~Au3_ScriptRestart_TempFile.au3" Local $sRunLine, $sScript_Content, $hFile $sRunLine = @ScriptFullPath If Not @Compiled Then $sRunLine = @AutoItExe & ' /AutoIt3ExecuteScript ""' & $sRunLine & '""' If $CmdLine[0] > 0 Then $sRunLine &= ' ' & $CmdLineRaw $sScript_Content &= '#NoTrayIcon' & @CRLF & _ 'While ProcessExists(' & @AutoItPID & ')' & @CRLF & _ ' Sleep(10)' & @CRLF & _ 'WEnd' & @CRLF & _ 'Run("' & $sRunLine & '")' & @CRLF & _ 'FileDelete(@ScriptFullPath)' & @CRLF $hFile = FileOpen($sAutoIt_File, 2) FileWrite($hFile, $sScript_Content) FileClose($hFile) Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & $sAutoIt_File & '"', @ScriptDir, @SW_HIDE) Sleep(1000) Exit EndFunc ;==>_restart Func _ReduceMemory($i_PID = -1) If $i_PID <> -1 Then Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID) $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0]) DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0]) Else $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1) EndIf Return $ai_Return[0] EndFunc ;==>_ReduceMemory Func pi() Return $pi EndFunc Func degrees() Return $degrees EndFunc ;Any other func that you want Func google() Return 'ShellExecute("iexplore.exe","http://www.google.com")' EndFunc Edited April 10, 2012 by lorenkinzel Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now