Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #cs ----------------------------------------------------------------------------
- AutoIt Version: 3.3.6.1
- Author: Alastor [ZKFA Team]
- Script Function:
- Una calculadora muy simple.
- #ce ----------------------------------------------------------------------------
- #include <ButtonConstants.au3>
- #include <EditConstants.au3>
- #include <GUIConstantsEx.au3>
- #include <WindowsConstants.au3>
- Global $Buffer = 0
- Global $Operacion = 0
- #region #GUI Calculadora 1.2.kxf
- $GUI = GUICreate("Calculadora 1.2", 253, 236, 191, 153)
- $Resultado = GUICtrlCreateInput("", 8, 8, 239, 24, BitOR($ES_RIGHT, $ES_AUTOHSCROLL, $ES_READONLY, $ES_NUMBER))
- GUICtrlSetFont($Resultado, 10, 400, 0, "MS Sans Serif")
- GUICtrlSetColor($Resultado, 0x0000FF)
- $Boton_Retroceso = GUICtrlCreateButton("Retroceso", 40, 40, 63, 29, $WS_GROUP)
- $Boton_CE = GUICtrlCreateButton("CE", 112, 40, 62, 29, $WS_GROUP)
- $Boton_C = GUICtrlCreateButton("C", 184, 40, 62, 29, $WS_GROUP)
- $Boton_7 = GUICtrlCreateButton("7", 8, 80, 36, 29, $WS_GROUP)
- $Boton_8 = GUICtrlCreateButton("8", 56, 80, 36, 29, $WS_GROUP)
- $Boton_9 = GUICtrlCreateButton("9", 104, 80, 36, 29, $WS_GROUP)
- $Boton_Dividir = GUICtrlCreateButton("/", 152, 80, 36, 29, $WS_GROUP)
- $Boton_4 = GUICtrlCreateButton("4", 8, 120, 36, 29, $WS_GROUP)
- $Boton_5 = GUICtrlCreateButton("5", 56, 120, 36, 29, $WS_GROUP)
- $Boton_6 = GUICtrlCreateButton("6", 104, 120, 36, 29, $WS_GROUP)
- $Boton_Multiplicar = GUICtrlCreateButton("*", 152, 120, 36, 29, $WS_GROUP)
- $Boton_1 = GUICtrlCreateButton("1", 8, 160, 36, 29, $WS_GROUP)
- $Boton_2 = GUICtrlCreateButton("2", 56, 160, 36, 29, $WS_GROUP)
- $Boton_3 = GUICtrlCreateButton("3", 104, 160, 36, 29, $WS_GROUP)
- $Boton_Restar = GUICtrlCreateButton("-", 152, 160, 36, 29, $WS_GROUP)
- $Boton_0 = GUICtrlCreateButton("0", 8, 200, 36, 29, $WS_GROUP)
- $Boton_Signo = GUICtrlCreateButton("+/-", 56, 200, 36, 29, $WS_GROUP)
- $Boton_Coma = GUICtrlCreateButton(",", 104, 200, 36, 29, $WS_GROUP)
- $Boton_Sumar = GUICtrlCreateButton("+", 152, 200, 36, 29, $WS_GROUP)
- $Boton_Igual = GUICtrlCreateButton("=", 199, 200, 44, 29, $WS_GROUP)
- GUICtrlSetFont($Boton_Igual, 10, 400, 0, "MS Sans Serif")
- #endregion #GUI Calculadora 1.2.kxf
- Local $AccelKeys[18][2] = [["{NUMPAD0}", $Boton_0], _
- ["{NUMPAD1}", $Boton_1], _
- ["{NUMPAD2}", $Boton_2], _
- ["{NUMPAD3}", $Boton_3], _
- ["{NUMPAD4}", $Boton_4], _
- ["{NUMPAD5}", $Boton_5], _
- ["{NUMPAD6}", $Boton_6], _
- ["{NUMPAD7}", $Boton_7], _
- ["{NUMPAD8}", $Boton_8], _
- ["{NUMPAD9}", $Boton_9], _
- ["{NUMPAD9}", $Boton_9], _
- ["{NUMPADSUB}", $Boton_Restar], _
- ["{NUMPADADD}", $Boton_Sumar], _
- ["{NUMPADMULT}", $Boton_Multiplicar], _
- ["{NUMPADDIV}", $Boton_Dividir], _
- ["{BACKSPACE}", $Boton_Retroceso], _
- ["{DELETE}", $Boton_CE], _
- ["{ENTER}", $Boton_Igual]]
- GUISetAccelerators($AccelKeys, $GUI)
- GUISetState(@SW_SHOW)
- While 1
- Switch GUIGetMsg()
- Case $GUI_EVENT_CLOSE ; Si se cierra la GUI
- Exit 0 ; Salir con codigo de error 0
- Case $Boton_Retroceso ; Boton para borrar el ultimo caracter
- $TxtActual = GUICtrlRead($Resultado) ; Se lee el numero actual
- $TxtMenos1 = StringTrimRight($TxtActual, 1) ; Se le quita el utlimo numero
- GUICtrlSetData($Resultado, $TxtMenos1) ; Se modifica
- Case $Boton_CE ; Boton para borrar todo
- $Buffer = 0 ; $Buffer se utiliza para guardar el numero anterior
- $Operacion = 0 ; $Operacion se utiliza para saber que operacion realizar
- GUICtrlSetData($Resultado, "") ; Se borra la input de resultados
- Case $Boton_C ; Boton para borrar solo la input de resultados
- GUICtrlSetData($Resultado, "")
- Case $Boton_1 ; Botones del 0 al 9 para agregar el numero correspondiente
- GUICtrlSetData($Resultado, '1', 0)
- Case $Boton_2
- GUICtrlSetData($Resultado, '2', 0)
- Case $Boton_3
- GUICtrlSetData($Resultado, '3', 0)
- Case $Boton_4
- GUICtrlSetData($Resultado, '4', 0)
- Case $Boton_5
- GUICtrlSetData($Resultado, '5', 0)
- Case $Boton_6
- GUICtrlSetData($Resultado, '6', 0)
- Case $Boton_7
- GUICtrlSetData($Resultado, '7', 0)
- Case $Boton_8
- GUICtrlSetData($Resultado, '8', 0)
- Case $Boton_9
- GUICtrlSetData($Resultado, '9', 0)
- Case $Boton_0
- GUICtrlSetData($Resultado, '0', 0)
- Case $Boton_Coma
- GUICtrlSetData($Resultado, ',', 0)
- Case $Boton_Signo ; Boton para modificar el signo actual (Negativo / Positivo)
- $TxtActual = GUICtrlRead($Resultado) ; Se lee el valor actual
- $Signo = StringLeft($TxtActual, 1) ; Se lee el primer caracter
- If $Signo == '-' Then ; Si es negativo
- $CambioDeSigno = StringTrimLeft($TxtActual, 1) ; Se borra el signo
- Else ; Si es positivo (No tiene signo)
- $CambioDeSigno = '-' & $TxtActual ; Se agrega el signo
- EndIf
- GUICtrlSetData($Resultado, $CambioDeSigno)
- Case $Boton_Dividir
- If $Operacion == 0 Then ; Si no hay ninguna operacion definida
- $Buffer = GUICtrlRead($Resultado) ; Se guarda el valor actual
- $Operacion = '/' ; Se define la operacion
- GUICtrlSetData($Resultado, "") ; Se borra la entrada de resultados
- Else
- $Operacion = '/' ; En caso contrario solo se modifica la operacion
- EndIf
- Case $Boton_Multiplicar
- If $Operacion == 0 Then
- $Buffer = GUICtrlRead($Resultado)
- $Operacion = '*'
- GUICtrlSetData($Resultado, "")
- Else
- $Operacion = '*'
- EndIf
- Case $Boton_Restar
- If $Operacion == 0 Then
- $Buffer = GUICtrlRead($Resultado)
- $Operacion = '-'
- GUICtrlSetData($Resultado, "")
- Else
- $Operacion = '-'
- EndIf
- Case $Boton_Sumar
- If $Operacion == 0 Then
- $Buffer = GUICtrlRead($Resultado)
- $Operacion = '+'
- GUICtrlSetData($Resultado, "")
- Else
- $Operacion = '+'
- EndIf
- Case $Boton_Igual
- If $Operacion = Not 0 Then ; Si hay una operacion definida
- $TxtActual = GUICtrlRead($Resultado) ; Se lee el valor actual
- $AnteriorArreglado = StringReplace($Buffer, ',', '.') ; Se reemplazan las comas por puntos (Para las operaciones decimales en autoit)
- $ActualArreglado = StringReplace($TxtActual, ',', '.')
- Switch $Operacion
- Case '+'
- $Result = $AnteriorArreglado + $ActualArreglado
- Case '-'
- $Result = $AnteriorArreglado - $ActualArreglado
- Case '*'
- $Result = $AnteriorArreglado * $ActualArreglado
- Case '/'
- $Result = $AnteriorArreglado / $ActualArreglado
- EndSwitch
- $ResultadoArreglado = StringReplace($Result, '.', ',') ; Se vuelven a poner puntos en lugar de comas
- GUICtrlSetData($Resultado, $ResultadoArreglado)
- $Buffer = 0
- $Operacion = 0
- EndIf
- EndSwitch
- WEnd
Advertisement
Add Comment
Please, Sign In to add comment