Author Topic: InForm Calculator by Terry Ritchie  (Read 2957 times)

0 Members and 1 Guest are viewing this topic.

Offline Junior Librarian

  • Moderator
  • Newbie
  • Posts: 19
InForm Calculator by Terry Ritchie
« on: September 24, 2021, 05:12:55 am »
InForm Calculator

Author: @TerryRitchie
Source: qb64.org Forum
URL: https://www.qb64.org/forum/index.php?topic=507.0
Version: 1

Description:
This is a calculator program I have been working on.  This little program gave me the general feel for InForm and got me back into programming QB64, a win-win.

Source Code:
Code: QB64: [Select]
  1.  
  2.     ':  ____ ____ ____ ____ ____ ____ ____ ____ ____ ____
  3.     ': ||C |||A |||L |||C |||U |||L |||A |||T |||O |||R ||
  4.     ': ||__|||__|||__|||__|||__|||__|||__|||__|||__|||__||
  5.     ': |/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|
  6.     ':
  7.     ': QB64 Calculator V1.0
  8.     ': Terry Ritchie - 08/29/18
  9.     ':
  10.     ': Built as a clone of the Windows 7 standard calculator
  11.     ': An exersize in getting to know the InForm library
  12.     ':
  13.     ': This program uses
  14.     ': InForm - GUI library for QB64 - Beta version 7
  15.     ': Fellippe Heitor, 2016-2018 - fellippe@qb64.org - [member=2]FellippeHeitor[/member]
  16.     ': https://github.com/FellippeHeitor/InForm
  17.     '----------------------------------------------------------------------------------------------------------------------
  18.      
  19.     ': Program constants: -------------------------------------------------------------------------------------------------
  20.      
  21.     CONST EQUATE = 0
  22.     CONST ADDITION = 1
  23.     CONST SUBTRACTION = 2
  24.     CONST MULTIPLICATION = 3
  25.     CONST DIVISION = 4
  26.      
  27.     ': Controls' IDs: -----------------------------------------------------------------------------------------------------
  28.      
  29.     DIM SHARED Calculator AS LONG
  30.     DIM SHARED frmResults AS LONG
  31.     DIM SHARED mnuEdit AS LONG
  32.     DIM SHARED mnuHelp AS LONG
  33.     DIM SHARED butMC AS LONG
  34.     DIM SHARED butMR AS LONG
  35.     DIM SHARED butMS AS LONG
  36.     DIM SHARED butMplus AS LONG
  37.     DIM SHARED butMminus AS LONG
  38.     DIM SHARED butBS AS LONG
  39.     DIM SHARED butCE AS LONG
  40.     DIM SHARED butC AS LONG
  41.     DIM SHARED butSign AS LONG
  42.     DIM SHARED butSQR AS LONG
  43.     DIM SHARED but7 AS LONG
  44.     DIM SHARED but8 AS LONG
  45.     DIM SHARED but9 AS LONG
  46.     DIM SHARED butDivide AS LONG
  47.     DIM SHARED butPercent AS LONG
  48.     DIM SHARED but4 AS LONG
  49.     DIM SHARED but5 AS LONG
  50.     DIM SHARED but6 AS LONG
  51.     DIM SHARED butMultiply AS LONG
  52.     DIM SHARED butReciprocate AS LONG
  53.     DIM SHARED but1 AS LONG
  54.     DIM SHARED but2 AS LONG
  55.     DIM SHARED but3 AS LONG
  56.     DIM SHARED butSubtract AS LONG
  57.     DIM SHARED but0 AS LONG
  58.     DIM SHARED butPoint AS LONG
  59.     DIM SHARED butAdd AS LONG
  60.     DIM SHARED butEqual AS LONG
  61.     DIM SHARED mnuCopy AS LONG
  62.     DIM SHARED mnuPaste AS LONG
  63.     DIM SHARED mnuAbout AS LONG
  64.     DIM SHARED lblAnswer AS LONG
  65.     DIM SHARED lblMemory AS LONG
  66.     DIM SHARED lblHistory AS LONG
  67.      
  68.     ': Program variables: -------------------------------------------------------------------------------------------------
  69.      
  70.     DIM SHARED operand$ '                       current operand
  71.     DIM SHARED history$ '                       calculation history
  72.     DIM SHARED operand1 AS DOUBLE '             first operand enetered
  73.     DIM SHARED operand2 AS DOUBLE '             second operand entered
  74.     DIM SHARED operator AS INTEGER '            current operator selected
  75.     DIM SHARED operator$(4)
  76.     DIM SHARED previousoperator AS INTEGER '    previous operator saved
  77.     DIM SHARED resetoperand AS INTEGER '        True when operand entry needs reset
  78.     DIM SHARED memory AS DOUBLE '               value stored in memory
  79.     DIM SHARED nohistory AS INTEGER
  80.      
  81.     ': External modules: --------------------------------------------------------------------------------------------------
  82.      
  83.     '$INCLUDE:'InForm\InForm.ui'
  84.     '$INCLUDE:'InForm\xp.uitheme'
  85.     '$INCLUDE:'Calculator.frm'
  86.      
  87.     ': Windows libraries : ------------------------------------------------------------------------------------------------
  88.      
  89.     ' Windows system sounds
  90.     ' Code contributed by QB64.org Wiki - Author unknown
  91.     ' http://qb64.org/wiki/Windows_Libraries#Windows_Sounds
  92.     ' Note: this Windows library will fail in SDL versions of QB64
  93.     '       change DECLARE LIBRARY to DECLARE DYNAMIC LIBRARY "Wimmm"
  94.     '       to allow this library to work with SDL versions of QB64
  95.      
  96.         FUNCTION PlaySound (pszSound AS STRING, BYVAL hmod AS INTEGER, BYVAL fdwSound AS INTEGER)
  97.     END DECLARE
  98.      
  99.     ': Program procedures: ------------------------------------------------------------------------------------------------
  100.      
  101.     '----------------------------------------------------------------------------------------------------------------------
  102.     SUB ALERT () '                                                                                                  ALERT()
  103.         '------------------------------------------------------------------------------------------------------------------
  104.      
  105.         ' Plays Windows default sounds
  106.         ' Sounds can be invoked using the following strings:
  107.         ' "SystemDefault","SystemExclamation","SystemExit","SystemHand","SystemQuestion","SystemStart","SystemWelcome"
  108.      
  109.         s = PlaySound("SystemDefault" + CHR$(0), 0, 65537) '                play Windows default system sound
  110.      
  111.     END SUB
  112.      
  113.     '----------------------------------------------------------------------------------------------------------------------
  114.     FUNCTION CLEAN$ (n AS DOUBLE) '                                                                                CLEAN$()
  115.         '------------------------------------------------------------------------------------------------------------------
  116.      
  117.         ' Return number (n) as a string with no leading/trailing spaces
  118.         ' Add leading zero if necessary
  119.      
  120.         DIM c$ ' n converted to a clean string
  121.      
  122.         c$ = LTRIM$(RTRIM$(STR$(n))) '                                      create clean string
  123.         IF ASC(c$, 1) = 46 THEN '                                           first character a decimal point?
  124.             c$ = "0" + c$ '                                                 yes, add leading zero
  125.         ELSEIF ASC(c$, 1) = 45 AND ASC(c$, 2) = 46 THEN '                   no, minus sign then decimal point?
  126.             c$ = "-0" + RIGHT$(c$, LEN(c$) - 1) '                           yes, add leading zero
  127.         END IF
  128.         CLEAN$ = c$ '                                                       return cleaned string
  129.      
  130.      
  131.     '----------------------------------------------------------------------------------------------------------------------
  132.     SUB UPDATEOPERAND (n$) '                                                                                UPDATEOPERAND()
  133.         '------------------------------------------------------------------------------------------------------------------
  134.      
  135.         ' Add user entries to operand
  136.         ' Keep operand to a max length of 16 numbers (not including decimal point)
  137.         ' Reset user operand input as needed
  138.         ' Keep leading zero for decimal values between one and negative one
  139.      
  140.         DIM olen AS INTEGER ' operand length
  141.      
  142.         IF resetoperand THEN '                                              new operand input?
  143.             operand$ = "" '                                                 yes, reset operand
  144.             resetoperand = False '                                          reset trigger
  145.         END IF
  146.         IF n$ = "." THEN '                                                  adding decimal point?
  147.             IF INSTR(operand$, ".") = 0 THEN '                              yes, already a decimal point?
  148.                 IF operand$ = "" THEN '                                     no, has operand been reset?
  149.                     n$ = "0." '                                             yes, add leading zero
  150.                 END IF
  151.             ELSE '                                                          yes, decimal point exists
  152.                 n$ = "" '                                                   ignore user request for decimal point
  153.             END IF
  154.         END IF
  155.         operand$ = operand$ + n$ '                                          update operand with user entry
  156.         olen = LEN(operand$) '                                              get length of operand
  157.         IF INSTR(operand$, ".") > 0 THEN olen = olen - 1 '                  don't count decimal point if preset
  158.         IF olen > 16 THEN operand$ = LEFT$(operand$, LEN(operand$) - 1) '   keep operand within 16 number limit
  159.      
  160.     END SUB
  161.      
  162.     '----------------------------------------------------------------------------------------------------------------------
  163.     SUB CALCULATE () '                                                                                          CALCULATE()
  164.         '------------------------------------------------------------------------------------------------------------------
  165.      
  166.         ' Calculate operand values based on operator previously used
  167.         ' Store result back into current operand
  168.      
  169.         SELECT CASE previousoperator '                                      which operator to use?
  170.             CASE ADDITION '                                                 add the operands
  171.                 operand$ = CLEAN$(operand1 + operand2) '                    perform clculation
  172.             CASE SUBTRACTION '                                              subtract the operands
  173.                 operand$ = CLEAN$(operand1 - operand2) '                    perform calculation
  174.             CASE MULTIPLICATION '                                           multiply the operands
  175.                 operand$ = CLEAN$(operand1 * operand2) '                    perform calculation
  176.             CASE DIVISION '                                                 divide the operands
  177.                 IF operand2 = 0 THEN '                                      dividing by zero?
  178.                     ALERT '                                                 get user's attention
  179.                     operand$ = "Can't divide by zero!" '                    yes, not in this universe!
  180.                 ELSE '                                                      no, physics is safe for now
  181.                     operand$ = CLEAN$(operand1 / operand2) '                perform calculation
  182.                 END IF
  183.         END SELECT
  184.         calculated = True
  185.      
  186.     END SUB
  187.      
  188.     '----------------------------------------------------------------------------------------------------------------------
  189.     SUB COMMITOPERAND () '                                                                                  COMMITOPERAND()
  190.         '------------------------------------------------------------------------------------------------------------------
  191.      
  192.         ' Get value of current operand
  193.         ' Calculate operands if necessary
  194.         ' Save current operand value
  195.         ' Remember the operator that invoked this routine
  196.      
  197.         operand2 = VAL(operand$) '                                          store value of current operand
  198.         IF previousoperator THEN '                                          previous operator selected?
  199.             CALCULATE '                                                     yes, calculate
  200.         END IF
  201.         operand1 = VAL(operand$) '                                          move current total to previous value
  202.         previousoperator = operator '                                       move current operator to previous operator
  203.         resetoperand = True '                                               trigger an operand reset
  204.      
  205.     END SUB
  206.      
  207.     '----------------------------------------------------------------------------------------------------------------------
  208.     SUB SCANKEYBOARD () '                                                                                    SCANKEYBOARD()
  209.         '------------------------------------------------------------------------------------------------------------------
  210.      
  211.         ' Scan the keyboard for user keystrokes
  212.         ' Invoke the appropriate button for the desired key
  213.      
  214.         DIM k$ ' key pressed by user
  215.         DIM ctrl AS INTEGER
  216.      
  217.         k$ = INKEY$ '                                                       look for a key press
  218.         IF k$ <> "" THEN '                                                  was a key pressed?
  219.             SELECT CASE k$ '                                                yes, which one?
  220.                 CASE "0" '                                                  zero key pressed
  221.                     __UI_Click (but0) '                                     manually click the zero button
  222.                 CASE "1" '                                                  etc..
  223.                     __UI_Click (but1) '                                     etc..
  224.                 CASE "2"
  225.                     __UI_Click (but2)
  226.                 CASE "3"
  227.                     __UI_Click (but3)
  228.                 CASE "4"
  229.                     __UI_Click (but4)
  230.                 CASE "5"
  231.                     __UI_Click (but5)
  232.                 CASE "6"
  233.                     __UI_Click (but6)
  234.                 CASE "7"
  235.                     __UI_Click (but7)
  236.                 CASE "8"
  237.                     __UI_Click (but8)
  238.                 CASE "9"
  239.                     __UI_Click (but9)
  240.                 CASE "."
  241.                     __UI_Click (butPoint)
  242.                 CASE "+"
  243.                     __UI_Click (butAdd)
  244.                 CASE "-"
  245.                     __UI_Click (butSubtract)
  246.                 CASE "*"
  247.                     __UI_Click (butMultiply)
  248.                 CASE "/"
  249.                     __UI_Click (butDivide)
  250.                 CASE "%"
  251.                     __UI_Click (butPercent)
  252.                 CASE "=", CHR$(13) '                                        treat ENTER and = the same
  253.                     __UI_Click (butEqual)
  254.                 CASE CHR$(8) '                                              backspace key pressed
  255.                     __UI_Click (butBS)
  256.      
  257.                 CASE "c", "C" '                                             CTRL-C copy
  258.                     ctrl = _KEYDOWN(100305) OR _KEYDOWN(100306)
  259.                     IF ctrl THEN BEEP
  260.      
  261.                     ' Will need to investigate how to capture CTRL-C and CTRL-V
  262.                     ' Neither the code above or below works
  263.      
  264.                 CASE "v", "V" '                                             CTRL-V paste
  265.                     IF __UI_CtrlIsDown THEN '                               is CTRL key presses?
  266.      
  267.                         BEEP
  268.      
  269.                     END IF
  270.      
  271.             END SELECT
  272.         END IF
  273.      
  274.     END SUB
  275.      
  276.     '----------------------------------------------------------------------------------------------------------------------
  277.     SUB ADDHISTORY (h$) '                                                                                      ADDHISTORY()
  278.         '------------------------------------------------------------------------------------------------------------------
  279.      
  280.         IF nohistory THEN
  281.             nohistory = False
  282.         ELSE
  283.             history$ = history$ + h$
  284.         END IF
  285.      
  286.     END SUB
  287.      
  288.     '----------------------------------------------------------------------------------------------------------------------
  289.      
  290.     ': Event procedures: --------------------------------------------------------------------------------------------------
  291.      
  292.     SUB __UI_BeforeInit
  293.      
  294.     END SUB
  295.      
  296.     SUB __UI_OnLoad
  297.      
  298.         operator$(1) = " + " ' define operator strings
  299.         operator$(2) = " - "
  300.         operator$(3) = " * "
  301.         operator$(4) = " / "
  302.      
  303.     END SUB
  304.      
  305.     SUB __UI_BeforeUpdateDisplay
  306.         'This event occurs at approximately 30 frames per second.
  307.         'You can change the update frequency by calling SetFrameRate DesiredRate%
  308.      
  309.         DIM answer$ ' current operand displayed
  310.      
  311.         SCANKEYBOARD '                                                      process keys pressed by user
  312.      
  313.         Caption(lblHistory) = history$ + operator$(operator) '              update history display
  314.      
  315.         answer$ = operand$ '                                                copy operand
  316.         IF answer$ = "" THEN answer$ = "0" '                                set to zero if empty
  317.      
  318.         Caption(lblAnswer) = answer$ '                                      display current operand
  319.      
  320.         IF memory THEN '                                                    does memory have value?
  321.             Caption(lblMemory) = "M" '                                      yes, apply screen indication
  322.         ELSE '                                                              no
  323.             Caption(lblMemory) = "" '                                       remove screen indication
  324.         END IF
  325.      
  326.     END SUB
  327.      
  328.     SUB __UI_BeforeUnload
  329.         'If you set __UI_UnloadSignal = False here you can
  330.         'cancel the user's request to close.
  331.      
  332.     END SUB
  333.      
  334.     SUB __UI_Click (id AS LONG)
  335.         SELECT CASE id
  336.             CASE Calculator
  337.      
  338.             CASE frmResults
  339.      
  340.             CASE mnuEdit
  341.      
  342.             CASE mnuHelp
  343.      
  344.                 ': memory buttons: ----------------------------------------------------------------------------------------
  345.      
  346.             CASE butMC '                                                    memory clear clicked
  347.                 memory = 0 '                                                reset memory value
  348.      
  349.             CASE butMR '                                                    memory recall clicked
  350.                 IF memory THEN '                                            memory available?
  351.                     operand$ = CLEAN$(memory) '                             Yes, make it the current operand
  352.                     resetoperand = True '                                   trigger an operand reset
  353.                 END IF
  354.      
  355.             CASE butMS '                                                    memory store clicked
  356.                 memory = VAL(operand$) '                                    overwrite memory with current operand
  357.                 resetoperand = True '                                       trigger an operand reset
  358.      
  359.             CASE butMplus '                                                 memory addition clicked
  360.                 memory = memory + VAL(operand$) '                           add current operand to memory
  361.                 resetoperand = True '                                       trigger an operand reset
  362.      
  363.             CASE butMminus '                                                memory subtraction clicked
  364.                 memory = memory - VAL(operand$) '                           subtract current operand from memory
  365.                 resetoperand = True '                                       trigger an operand reset
  366.      
  367.                 ': clear buttons: -----------------------------------------------------------------------------------------
  368.      
  369.             CASE butCE '                                                    clear entry clicked
  370.                 operand$ = "" '                                             reset current operand
  371.      
  372.             CASE butC '                                                     clear clicked
  373.                 operand1 = 0 '                                              initialize all values
  374.                 operand2 = 0
  375.                 operator = 0
  376.                 previousoperator = 0
  377.                 operand$ = ""
  378.                 history$ = ""
  379.      
  380.             CASE butBS '                                                    backspace clicked
  381.                 IF LEN(operand$) THEN '                                     characters in operand?
  382.                     operand$ = LEFT$(operand$, LEN(operand$) - 1) '         yes, remove right-most character
  383.                 END IF
  384.      
  385.                 ': calculation buttons: -----------------------------------------------------------------------------------
  386.      
  387.             CASE butReciprocate '                                           reciprocate clicked
  388.                 IF VAL(operand$) THEN '                                     dividing by zero?
  389.      
  390.                     ADDHISTORY (operator$(previousoperator) + "Reciproc(" + operand$ + ")")
  391.                     nohistory = True '                                      skip operand history next time
  392.                     operator = EQUATE
  393.      
  394.                     operand$ = CLEAN$(1 / VAL(operand$)) '                  no, calculate reciprocate
  395.                 ELSE '                                                      yes, physics will collapse!
  396.                     ALERT '                                                 get user's attention
  397.                     operand$ = "Can't divide by zero!" '                    report error to user
  398.                 END IF
  399.                 resetoperand = True '                                       trigger an operand reset
  400.      
  401.             CASE butSQR '                                                   square root clicked
  402.                 IF VAL(operand$) >= 0 THEN '                                positive value?
  403.      
  404.                     ADDHISTORY (operator$(previousoperator) + "SQRT(" + operand$ + ")")
  405.                     nohistory = True '                                      skip operand history next time
  406.                     operator = EQUATE
  407.      
  408.                     operand$ = CLEAN$(SQR(VAL(operand$))) '                 yes, calculate square root
  409.                 ELSE '                                                      no, value is negative
  410.                     ALERT '                                                 get user's attention
  411.                     operand$ = "Invalid input!" '                           nice try buddy
  412.                 END IF
  413.                 resetoperand = True '                                       trigger an operand reset
  414.      
  415.             CASE butPercent '                                               percent clicked
  416.                 operand$ = CLEAN$(operand1 * VAL(operand$) / 100) '         calculate percentage of previous operand
  417.                 resetoperand = True
  418.      
  419.             CASE butSign '                                                  sign clicked
  420.                 IF VAL(operand$) THEN '                                     value equal to zero?
  421.                     operand$ = CLEAN$(-VAL(operand$)) '                     no, reverse sign of operand
  422.                 END IF
  423.      
  424.                 ': number buttons: ----------------------------------------------------------------------------------------
  425.      
  426.             CASE but0 '                                                     zero clicked
  427.                 IF VAL(operand$) OR INSTR(operand$, ".") THEN '             ok to add a zero?
  428.                     UPDATEOPERAND ("0") '                                   yes, append zero
  429.                 END IF
  430.      
  431.             CASE but1 '                                                     one clicked
  432.                 UPDATEOPERAND ("1") '                                       append one
  433.      
  434.             CASE but2 '                                                     etc..
  435.                 UPDATEOPERAND ("2") '                                       etc..
  436.      
  437.             CASE but3
  438.                 UPDATEOPERAND ("3")
  439.      
  440.             CASE but4
  441.                 UPDATEOPERAND ("4")
  442.      
  443.             CASE but5
  444.                 UPDATEOPERAND ("5")
  445.      
  446.             CASE but6
  447.                 UPDATEOPERAND ("6")
  448.      
  449.             CASE but7
  450.                 UPDATEOPERAND ("7")
  451.      
  452.             CASE but8
  453.                 UPDATEOPERAND ("8")
  454.      
  455.             CASE but9
  456.                 UPDATEOPERAND ("9")
  457.      
  458.             CASE butPoint
  459.                 UPDATEOPERAND (".")
  460.      
  461.                 ': operator buttons: --------------------------------------------------------------------------------------
  462.      
  463.             CASE butDivide '                                                divide clicked
  464.      
  465.                 ADDHISTORY (operator$(previousoperator) + operand$)
  466.      
  467.                 operator = DIVISION '                                       remember operator selected
  468.                 COMMITOPERAND '                                             save operand
  469.      
  470.             CASE butMultiply '                                              multiply clicked
  471.      
  472.                 ADDHISTORY (operator$(previousoperator) + operand$)
  473.      
  474.                 operator = MULTIPLICATION '                                 remember operator selected
  475.                 COMMITOPERAND '                                             save operand
  476.      
  477.             CASE butSubtract '                                              subtract clicked
  478.      
  479.                 ADDHISTORY (operator$(previousoperator) + operand$)
  480.      
  481.                 operator = SUBTRACTION '                                    remember operator selected
  482.                 COMMITOPERAND '                                             save operand
  483.      
  484.             CASE butAdd '                                                   addition clicked
  485.      
  486.                 ADDHISTORY (operator$(previousoperator) + operand$)
  487.      
  488.                 operator = ADDITION '                                       remember operator selected
  489.                 COMMITOPERAND '                                             save operand
  490.      
  491.             CASE butEqual '                                                 equal clicked
  492.      
  493.                 history$ = ""
  494.                 operator = EQUATE '                                         remember operator selected
  495.                 COMMITOPERAND '                                             save operand
  496.                 previousoperator = 0
  497.      
  498.      
  499.             CASE mnuCopy
  500.      
  501.             CASE mnuPaste
  502.      
  503.             CASE mnuAbout
  504.                 operand$ = "InForm Calculator 1.0"
  505.                 resetoperand = True
  506.      
  507.             CASE lblAnswer
  508.      
  509.             CASE lblMemory
  510.      
  511.             CASE lblHistory
  512.      
  513.         END SELECT
  514.     END SUB
  515.      
  516.     SUB __UI_MouseEnter (id AS LONG)
  517.         SELECT CASE id
  518.             CASE Calculator
  519.      
  520.             CASE frmResults
  521.      
  522.             CASE mnuEdit
  523.      
  524.             CASE mnuHelp
  525.      
  526.             CASE butMC
  527.      
  528.             CASE butMR
  529.      
  530.             CASE butMS
  531.      
  532.             CASE butMplus
  533.      
  534.             CASE butMminus
  535.      
  536.             CASE butBS
  537.      
  538.             CASE butCE
  539.      
  540.             CASE butC
  541.      
  542.             CASE butSign
  543.      
  544.             CASE butSQR
  545.      
  546.             CASE but7
  547.      
  548.             CASE but8
  549.      
  550.             CASE but9
  551.      
  552.             CASE butDivide
  553.      
  554.             CASE butPercent
  555.      
  556.             CASE but4
  557.      
  558.             CASE but5
  559.      
  560.             CASE but6
  561.      
  562.             CASE butMultiply
  563.      
  564.             CASE butReciprocate
  565.      
  566.             CASE but1
  567.      
  568.             CASE but2
  569.      
  570.             CASE but3
  571.      
  572.             CASE butSubtract
  573.      
  574.             CASE but0
  575.      
  576.             CASE butPoint
  577.      
  578.             CASE butAdd
  579.      
  580.             CASE butEqual
  581.      
  582.             CASE mnuCopy
  583.      
  584.             CASE mnuPaste
  585.      
  586.             CASE mnuAbout
  587.      
  588.             CASE lblAnswer
  589.      
  590.             CASE lblMemory
  591.      
  592.             CASE lblHistory
  593.      
  594.         END SELECT
  595.     END SUB
  596.      
  597.     SUB __UI_MouseLeave (id AS LONG)
  598.         SELECT CASE id
  599.             CASE Calculator
  600.      
  601.             CASE frmResults
  602.      
  603.             CASE mnuEdit
  604.      
  605.             CASE mnuHelp
  606.      
  607.             CASE butMC
  608.      
  609.             CASE butMR
  610.      
  611.             CASE butMS
  612.      
  613.             CASE butMplus
  614.      
  615.             CASE butMminus
  616.      
  617.             CASE butBS
  618.      
  619.             CASE butCE
  620.      
  621.             CASE butC
  622.      
  623.             CASE butSign
  624.      
  625.             CASE butSQR
  626.      
  627.             CASE but7
  628.      
  629.             CASE but8
  630.      
  631.             CASE but9
  632.      
  633.             CASE butDivide
  634.      
  635.             CASE butPercent
  636.      
  637.             CASE but4
  638.      
  639.             CASE but5
  640.      
  641.             CASE but6
  642.      
  643.             CASE butMultiply
  644.      
  645.             CASE butReciprocate
  646.      
  647.             CASE but1
  648.      
  649.             CASE but2
  650.      
  651.             CASE but3
  652.      
  653.             CASE butSubtract
  654.      
  655.             CASE but0
  656.      
  657.             CASE butPoint
  658.      
  659.             CASE butAdd
  660.      
  661.             CASE butEqual
  662.      
  663.             CASE mnuCopy
  664.      
  665.             CASE mnuPaste
  666.      
  667.             CASE mnuAbout
  668.      
  669.             CASE lblAnswer
  670.      
  671.             CASE lblMemory
  672.      
  673.             CASE lblHistory
  674.      
  675.         END SELECT
  676.     END SUB
  677.      
  678.     SUB __UI_FocusIn (id AS LONG)
  679.         SELECT CASE id
  680.             CASE butMC
  681.      
  682.             CASE butMR
  683.      
  684.             CASE butMS
  685.      
  686.             CASE butMplus
  687.      
  688.             CASE butMminus
  689.      
  690.             CASE butBS
  691.      
  692.             CASE butCE
  693.      
  694.             CASE butC
  695.      
  696.             CASE butSign
  697.      
  698.             CASE butSQR
  699.      
  700.             CASE but7
  701.      
  702.             CASE but8
  703.      
  704.             CASE but9
  705.      
  706.             CASE butDivide
  707.      
  708.             CASE butPercent
  709.      
  710.             CASE but4
  711.      
  712.             CASE but5
  713.      
  714.             CASE but6
  715.      
  716.             CASE butMultiply
  717.      
  718.             CASE butReciprocate
  719.      
  720.             CASE but1
  721.      
  722.             CASE but2
  723.      
  724.             CASE but3
  725.      
  726.             CASE butSubtract
  727.      
  728.             CASE but0
  729.      
  730.             CASE butPoint
  731.      
  732.             CASE butAdd
  733.      
  734.             CASE butEqual
  735.      
  736.         END SELECT
  737.     END SUB
  738.      
  739.     SUB __UI_FocusOut (id AS LONG)
  740.         'This event occurs right before a control loses focus.
  741.         'To prevent a control from losing focus, set __UI_KeepFocus = True below.
  742.         SELECT CASE id
  743.             CASE butMC
  744.      
  745.             CASE butMR
  746.      
  747.             CASE butMS
  748.      
  749.             CASE butMplus
  750.      
  751.             CASE butMminus
  752.      
  753.             CASE butBS
  754.      
  755.             CASE butCE
  756.      
  757.             CASE butC
  758.      
  759.             CASE butSign
  760.      
  761.             CASE butSQR
  762.      
  763.             CASE but7
  764.      
  765.             CASE but8
  766.      
  767.             CASE but9
  768.      
  769.             CASE butDivide
  770.      
  771.             CASE butPercent
  772.      
  773.             CASE but4
  774.      
  775.             CASE but5
  776.      
  777.             CASE but6
  778.      
  779.             CASE butMultiply
  780.      
  781.             CASE butReciprocate
  782.      
  783.             CASE but1
  784.      
  785.             CASE but2
  786.      
  787.             CASE but3
  788.      
  789.             CASE butSubtract
  790.      
  791.             CASE but0
  792.      
  793.             CASE butPoint
  794.      
  795.             CASE butAdd
  796.      
  797.             CASE butEqual
  798.      
  799.         END SELECT
  800.     END SUB
  801.      
  802.     SUB __UI_MouseDown (id AS LONG)
  803.         SELECT CASE id
  804.             CASE Calculator
  805.      
  806.             CASE frmResults
  807.      
  808.             CASE mnuEdit
  809.      
  810.             CASE mnuHelp
  811.      
  812.             CASE butMC
  813.      
  814.             CASE butMR
  815.      
  816.             CASE butMS
  817.      
  818.             CASE butMplus
  819.      
  820.             CASE butMminus
  821.      
  822.             CASE butBS
  823.      
  824.             CASE butCE
  825.      
  826.             CASE butC
  827.      
  828.             CASE butSign
  829.      
  830.             CASE butSQR
  831.      
  832.             CASE but7
  833.      
  834.             CASE but8
  835.      
  836.             CASE but9
  837.      
  838.             CASE butDivide
  839.      
  840.             CASE butPercent
  841.      
  842.             CASE but4
  843.      
  844.             CASE but5
  845.      
  846.             CASE but6
  847.      
  848.             CASE butMultiply
  849.      
  850.             CASE butReciprocate
  851.      
  852.             CASE but1
  853.      
  854.             CASE but2
  855.      
  856.             CASE but3
  857.      
  858.             CASE butSubtract
  859.      
  860.             CASE but0
  861.      
  862.             CASE butPoint
  863.      
  864.             CASE butAdd
  865.      
  866.             CASE butEqual
  867.      
  868.             CASE mnuCopy
  869.      
  870.             CASE mnuPaste
  871.      
  872.             CASE mnuAbout
  873.      
  874.             CASE lblAnswer
  875.      
  876.             CASE lblMemory
  877.      
  878.             CASE lblHistory
  879.      
  880.         END SELECT
  881.     END SUB
  882.      
  883.     SUB __UI_MouseUp (id AS LONG)
  884.         SELECT CASE id
  885.             CASE Calculator
  886.      
  887.             CASE frmResults
  888.      
  889.             CASE mnuEdit
  890.      
  891.             CASE mnuHelp
  892.      
  893.             CASE butMC
  894.      
  895.             CASE butMR
  896.      
  897.             CASE butMS
  898.      
  899.             CASE butMplus
  900.      
  901.             CASE butMminus
  902.      
  903.             CASE butBS
  904.      
  905.             CASE butCE
  906.      
  907.             CASE butC
  908.      
  909.             CASE butSign
  910.      
  911.             CASE butSQR
  912.      
  913.             CASE but7
  914.      
  915.             CASE but8
  916.      
  917.             CASE but9
  918.      
  919.             CASE butDivide
  920.      
  921.             CASE butPercent
  922.      
  923.             CASE but4
  924.      
  925.             CASE but5
  926.      
  927.             CASE but6
  928.      
  929.             CASE butMultiply
  930.      
  931.             CASE butReciprocate
  932.      
  933.             CASE but1
  934.      
  935.             CASE but2
  936.      
  937.             CASE but3
  938.      
  939.             CASE butSubtract
  940.      
  941.             CASE but0
  942.      
  943.             CASE butPoint
  944.      
  945.             CASE butAdd
  946.      
  947.             CASE butEqual
  948.      
  949.             CASE mnuCopy
  950.      
  951.             CASE mnuPaste
  952.      
  953.             CASE mnuAbout
  954.      
  955.             CASE lblAnswer
  956.      
  957.             CASE lblMemory
  958.      
  959.             CASE lblHistory
  960.      
  961.         END SELECT
  962.     END SUB
  963.      
  964.     SUB __UI_KeyPress (id AS LONG)
  965.         'When this event is fired, __UI_KeyHit will contain the code of the key hit.
  966.         'You can change it and even cancel it by making it = 0
  967.      
  968.         SELECT CASE id
  969.             CASE butMC
  970.      
  971.             CASE butMR
  972.      
  973.             CASE butMS
  974.      
  975.             CASE butMplus
  976.      
  977.             CASE butMminus
  978.      
  979.             CASE butBS
  980.      
  981.             CASE butCE
  982.      
  983.             CASE butC
  984.      
  985.             CASE butSign
  986.      
  987.             CASE butSQR
  988.      
  989.             CASE but7
  990.      
  991.             CASE but8
  992.      
  993.             CASE but9
  994.      
  995.             CASE butDivide
  996.      
  997.             CASE butPercent
  998.      
  999.             CASE but4
  1000.      
  1001.             CASE but5
  1002.      
  1003.             CASE but6
  1004.      
  1005.             CASE butMultiply
  1006.      
  1007.             CASE butReciprocate
  1008.      
  1009.             CASE but1
  1010.      
  1011.             CASE but2
  1012.      
  1013.             CASE but3
  1014.      
  1015.             CASE butSubtract
  1016.      
  1017.             CASE but0
  1018.      
  1019.             CASE butPoint
  1020.      
  1021.             CASE butAdd
  1022.      
  1023.             CASE butEqual
  1024.      
  1025.         END SELECT
  1026.     END SUB
  1027.      
  1028.     SUB __UI_TextChanged (id AS LONG)
  1029.         SELECT CASE id
  1030.         END SELECT
  1031.     END SUB
  1032.      
  1033.     SUB __UI_ValueChanged (id AS LONG)
  1034.         SELECT CASE id
  1035.         END SELECT
  1036.     END SUB
  1037.      
  1038.     SUB __UI_FormResized
  1039.      
  1040.     END SUB
  1041.  

Calculator Screenshot.jpg

 
                                                                                                                                         (175 downloads previously)