Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

basic simple calculator :)


  • Please log in to reply
5 replies to this topic

#1 ludocus

ludocus

    Possibly inventive crap going on right here

  • Active Members
  • PipPipPipPipPipPip
  • 668 posts

Posted 13 May 2008 - 03:29 PM

I made this basic calculator, its basic but pretty handy I would say.. :)
Hope you enjoy!
AutoIt         
#cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.10.0 Author: ludocus Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <GUIConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Lc", 116, 225, 193, 125) GUISetBkColor(0xFFFF00) $1 = GUICtrlCreateButton("1", 8, 40, 27, 25, 0) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") ;GUICtrlSetColor(-1, 0x800000) $2 = GUICtrlCreateButton("2", 40, 40, 27, 25, 0) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") ;GUICtrlSetColor(-1, 0x800000) $3 = GUICtrlCreateButton("3", 72, 40, 27, 25, 0) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") ;GUICtrlSetColor(-1, 0x800000) $4 = GUICtrlCreateButton("4", 8, 72, 27, 25, 0) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") ;GUICtrlSetColor(-1, 0x800000) $5 = GUICtrlCreateButton("5", 40, 72, 27, 25, 0) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") ;GUICtrlSetColor(-1, 0x800000) $6 = GUICtrlCreateButton("6", 72, 72, 27, 25, 0) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") ;GUICtrlSetColor(-1, 0x800000) $7 = GUICtrlCreateButton("7", 8, 104, 27, 25, 0) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") ;GUICtrlSetColor(-1, 0x800000) $8 = GUICtrlCreateButton("8", 40, 104, 27, 25, 0) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") ;GUICtrlSetColor(-1, 0x800000) $9 = GUICtrlCreateButton("9", 72, 104, 27, 25, 0) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") ;GUICtrlSetColor(-1, 0x800000) $o = GUICtrlCreateButton("0", 40, 136, 27, 25, 0) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") ;GUICtrlSetColor(-1, 0x800000) $min = GUICtrlCreateButton("-", 8, 136, 27, 25, 0) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") ;GUICtrlSetColor(-1, 0x800000) $plus = GUICtrlCreateButton("+", 72, 136, 27, 25, 0) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") ;GUICtrlSetColor(-1, 0x800000) $som = GUICtrlCreateInput("", 8, 8, 89, 21) $clear = GUICtrlCreateButton('c', 97, 8, 20, 20 ) $deel = GUICtrlCreateButton("/", 8, 168, 27, 25, 0) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") ;GUICtrlSetColor(-1, 0x800000) $keer = GUICtrlCreateButton("x", 40, 168, 27, 25, 0) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") ;GUICtrlSetColor(-1, 0x800000) $c = GUICtrlCreateButton(",", 72, 168, 27, 25, 0) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") ;GUICtrlSetColor(-1, 0x800000) $is = GUICtrlCreateButton("=", 8, 200, 92, 25, 0) GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif") ;GUICtrlSetColor(-1, 0x800000) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $1 calc(1) Case $2 calc(2) Case $3 calc(3) Case $4 calc(4) Case $5 calc(5) Case $6 calc(6) Case $7 calc(7) Case $8 calc(8) Case $9 calc(9) Case $o calc('nul') Case $deel calc('/') Case $keer calc('x') Case $is calc('get') Case $plus calc('+') Case $min calc('-') Case $c calc('.') Case $clear GUICtrlSetData($som, '' ) EndSwitch WEnd func calc($num) if $num='get' then get() Else if $num='nul' then GUICtrlSetData($som, GUICtrlRead($som)&0) Else GUICtrlSetData($som, GUICtrlRead($som)&$num) EndIf EndIf EndFunc func get() $p = Execute(StringReplace(GUICtrlRead($som), 'x', '*')) if @error then GUICtrlSetData($som, 'Error' ) Else GUICtrlSetData($som, $p ) EndIf EndFunc


Screenshot:
Posted Image

Edited by ludocus, 28 August 2008 - 10:02 AM.








#2 ludocus

ludocus

    Possibly inventive crap going on right here

  • Active Members
  • PipPipPipPipPipPip
  • 668 posts

Posted 14 May 2008 - 10:29 AM

comments???

#3 ACS

ACS

    Wayfarer

  • Active Members
  • Pip
  • 73 posts

Posted 14 May 2008 - 12:49 PM

Case $1 calc(1) Case $2 calc(2) Case $3 calc(3) Case $4 calc(4) Case $5 calc(5)


Could this not be cleaned up? Quite inefficient...

#4 smashly

smashly

  • Active Members
  • PipPipPipPipPipPip
  • 1,636 posts

Posted 14 May 2008 - 02:03 PM

Thank You for sharing, keep up the good effort.
As ACS said (even though the way it was said sounded a bit harsh to me) you could make the code briefer by using loops or multiple Case values per case.
AutoIt         
#include <GUIConstants.au3> Opt("GUIOnEventMode", 1) Global $SSB = StringSplit("1|2|3|4|5|6|7|8|9|-|0|+|/|*|.|C|%|=", "|"), $bX = 8, $bY = 40 $Form1 = GUICreate("Lc", 108, 233, 193, 125) GUISetOnEvent($GUI_EVENT_CLOSE, "Close", $Form1) GUISetBkColor(0xFFFF00) $som = GUICtrlCreateInput("", 8, 8, 89, 21) For $i = 1 To $SSB[0]     GUICtrlCreateButton($SSB[$i], $bX, $bY, 27, 25, $BS_CENTER)     GUICtrlSetOnEvent(-1, "Event")     GUICtrlSetFont(-1, 10, 700, 0, "MS Sans Serif")     If Not Mod($i, 3) Then         $bX = 8         $bY += 32     Else         $bX += 32     EndIf Next $SSB = 0 GUISetState(@SW_SHOW) While 1     Sleep(100) WEnd Func Event()     Switch GUICtrlRead(@GUI_CtrlId)         Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "-", "*", "/", "."             GUICtrlSetData($som,  GUICtrlRead($som) & GUICtrlRead(@GUI_CtrlId))         Case "="             If Execute(GUICtrlRead($som)) Then GUICtrlSetData($som, Execute(GUICtrlRead($som)))         Case "C"             GUICtrlSetData($som, "")         Case "%"             ;??? Percent, leave this one for you :P     EndSwitch EndFunc Func Close()     Exit EndFunc

Cheers

Edited by smashly, 14 May 2008 - 02:24 PM.


#5 Andreik

Andreik

    Bishop

  • Active Members
  • PipPipPipPipPipPip
  • 2,587 posts

Posted 14 May 2008 - 02:15 PM

Nice script! :)
When the words fail... music speaks

#6 ludocus

ludocus

    Possibly inventive crap going on right here

  • Active Members
  • PipPipPipPipPipPip
  • 668 posts

Posted 28 August 2008 - 10:02 AM

thnx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users