home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 April B / Pcwk4b98.iso / Borland / Dbase50w / SAMPLES1.PAK / CAL.WFM < prev    next >
Text File  |  1994-08-02  |  23KB  |  758 lines

  1. *******************************************************************************
  2. *  PROGRAM:      Cal.wfm
  3. *
  4. *  WRITTEN BY:   Borland Samples Group
  5. *
  6. *  DATE:         5/93
  7. *
  8. *  UPDATED:      6/94
  9. *
  10. *  REVISION:     $Revision:   2.77  $
  11. *
  12. *  VERSION:      dBASE FOR WINDOWS 5.0
  13. *
  14. *  DESCRIPTION:  This file contains a calculator form.  This calculator
  15. *                contains pushbuttons for numeric input and operations.  It also
  16. *                contains 2 entryfields -- the main display, showing the current
  17. *                calculation, and a memory display, showing current memory
  18. *                contents.  Calculations can be performed in either decimal
  19. *                or hexadecimal systems.
  20. *
  21. *  PARAMETERS:   None
  22. *
  23. *  CALLS:        None
  24. *
  25. *  USAGE:        DO Cal.wfm
  26. *
  27. *******************************************************************************
  28. #define MAX_DEC_DIGITS      18
  29. #define MAX_HEX_DIGITS      8
  30. #define OVERFLOW            2^32
  31.  
  32. create session   && there are no tables in this program, but
  33.                  && this line ensures that the variable names used
  34.                  && here don't refer to any tables opened previously
  35. set talk off
  36. set ldCheck off
  37.  
  38. ** END HEADER -- do not remove this line*
  39. * Generated on 06/03/94
  40. *
  41. LOCAL f
  42. f = NEW CALFORM()
  43. f.Open()
  44.  
  45. CLASS CALFORM OF FORM
  46.    this.MousePointer =          1
  47.    this.Width =         41.57
  48.    this.Top =          0.76
  49.    this.Left =         13.53
  50.    this.Height =         17.34
  51.    this.Text = "Calculator"
  52.    this.Minimize = .F.
  53.    this.Maximize = .F.
  54.    this.HelpFile = ""
  55.    this.HelpId = ""
  56.    this.OnOpen = CLASS::ONOPEN
  57.    this.OnGotFocus = CLASS::ONGOTFOCUS
  58.    this.OnLostFocus = CLASS::ONLOSTFOCUS
  59.  
  60.    DEFINE RECTANGLE RECTANGLE2 OF THIS;
  61.        PROPERTY;
  62.          Width         40.26,;
  63.          Top         12.38,;
  64.          Left          0.66,;
  65.          Height          2.76,;
  66.          Text "",;
  67.          ColorNormal "N/W",;
  68.          Border .T.,;
  69.          BorderStyle          1
  70.  
  71.    DEFINE RECTANGLE RECTANGLE1 OF THIS;
  72.        PROPERTY;
  73.          Width         40.26,;
  74.          Top          2.20,;
  75.          Left          0.66,;
  76.          Height          10.18,;
  77.          Text "",;
  78.          ColorNormal "N/W",;
  79.          Border .T.,;
  80.          BorderStyle          1
  81.  
  82.    DEFINE ENTRYFIELD DISPLAY OF THIS;
  83.        PROPERTY;
  84.          Value "                 0",;
  85.          FontSize         15.00,;
  86.          Width         40.26,;
  87.          FontName "Courier New",;
  88.          Top          0.27,;
  89.          Left          0.66,;
  90.          Height          1.66,;
  91.          Function "J",;
  92.          ColorNormal "N/BG*",;
  93.          Border .T.,;
  94.          Enabled .F.
  95.  
  96.    DEFINE PUSHBUTTON B7 OF THIS;
  97.        PROPERTY;
  98.          Width          5.28,;
  99.          Top          2.47,;
  100.          Left          1.98,;
  101.          OnClick CLASS::NUMERIC_CLICK,;
  102.          Height          2.20,;
  103.          Text "7",;
  104.          Default .F.,;
  105.          ColorNormal "B/W"
  106.  
  107.    DEFINE PUSHBUTTON B8 OF THIS;
  108.        PROPERTY;
  109.          Width          5.28,;
  110.          Top          2.47,;
  111.          Left          7.92,;
  112.          OnClick CLASS::NUMERIC_CLICK,;
  113.          Height          2.20,;
  114.          Text "8",;
  115.          ColorNormal "B/W"
  116.  
  117.    DEFINE PUSHBUTTON B9 OF THIS;
  118.        PROPERTY;
  119.          Width          5.28,;
  120.          Top          2.47,;
  121.          Left         13.86,;
  122.          OnClick CLASS::NUMERIC_CLICK,;
  123.          Height          2.20,;
  124.          Text "9",;
  125.          ColorNormal "B/W"
  126.  
  127.    DEFINE PUSHBUTTON B4 OF THIS;
  128.        PROPERTY;
  129.          Width          5.28,;
  130.          Top          4.96,;
  131.          Left          1.98,;
  132.          OnClick CLASS::NUMERIC_CLICK,;
  133.          Height          2.20,;
  134.          Text "4",;
  135.          ColorNormal "B/W"
  136.  
  137.    DEFINE PUSHBUTTON B5 OF THIS;
  138.        PROPERTY;
  139.          Width          5.28,;
  140.          Top          4.96,;
  141.          Left          7.92,;
  142.          OnClick CLASS::NUMERIC_CLICK,;
  143.          Height          2.20,;
  144.          Text "5",;
  145.          ColorNormal "B/W"
  146.  
  147.    DEFINE PUSHBUTTON B6 OF THIS;
  148.        PROPERTY;
  149.          Width          5.28,;
  150.          Top          4.96,;
  151.          Left         13.86,;
  152.          OnClick CLASS::NUMERIC_CLICK,;
  153.          Height          2.20,;
  154.          Text "6",;
  155.          ColorNormal "B/W"
  156.  
  157.    DEFINE PUSHBUTTON B1 OF THIS;
  158.        PROPERTY;
  159.          Width          5.28,;
  160.          Top          7.43,;
  161.          Left          1.98,;
  162.          OnClick CLASS::NUMERIC_CLICK,;
  163.          Height          2.20,;
  164.          Text "1",;
  165.          Default .F.,;
  166.          ColorNormal "B/W"
  167.  
  168.    DEFINE PUSHBUTTON B2 OF THIS;
  169.        PROPERTY;
  170.          Width          5.28,;
  171.          Top          7.43,;
  172.          Left          7.92,;
  173.          OnClick CLASS::NUMERIC_CLICK,;
  174.          Height          2.20,;
  175.          Text "2",;
  176.          ColorNormal "B/W"
  177.  
  178.    DEFINE PUSHBUTTON B3 OF THIS;
  179.        PROPERTY;
  180.          Width          5.28,;
  181.          Top          7.43,;
  182.          Left         13.86,;
  183.          OnClick CLASS::NUMERIC_CLICK,;
  184.          Height          2.20,;
  185.          Text "3",;
  186.          ColorNormal "B/W"
  187.  
  188.    DEFINE PUSHBUTTON OPPLUSMINUS OF THIS;
  189.        PROPERTY;
  190.          FontSize          9.00,;
  191.          Width          5.28,;
  192.          FontName "MS Serif",;
  193.          Top          9.91,;
  194.          Left          1.98,;
  195.          OnClick CLASS::PLUSMINUS_CLICK,;
  196.          Height          2.20,;
  197.          Text "+/-",;
  198.          ColorNormal "N/W"
  199.  
  200.    DEFINE PUSHBUTTON B0 OF THIS;
  201.        PROPERTY;
  202.          Width          5.28,;
  203.          Top          9.91,;
  204.          Left          7.92,;
  205.          OnClick CLASS::NUMERIC_CLICK,;
  206.          Height          2.20,;
  207.          Text "0",;
  208.          ColorNormal "B/W"
  209.  
  210.    DEFINE PUSHBUTTON PERIOD OF THIS;
  211.        PROPERTY;
  212.          Text          " ",;
  213.          Width          5.28,;
  214.          Top          9.91,;
  215.          Left         13.86,;
  216.          OnClick CLASS::PERIOD_CLICK,;
  217.          Height          2.20,;
  218.          ColorNormal "N/W"
  219.  
  220.    DEFINE PUSHBUTTON OPPOWER OF THIS;
  221.        PROPERTY;
  222.          FontSize          9.00,;
  223.          Width          5.28,;
  224.          FontName "MS Serif",;
  225.          Top          2.47,;
  226.          Left         21.12,;
  227.          OnClick CLASS::OP_CLICK,;
  228.          Height          2.20,;
  229.          Text "^",;
  230.          ColorNormal "N/W"
  231.  
  232.    DEFINE PUSHBUTTON OPTIMES OF THIS;
  233.        PROPERTY;
  234.          FontSize          9.00,;
  235.          Width          5.28,;
  236.          FontName "MS Serif",;
  237.          Top          4.96,;
  238.          Left         21.12,;
  239.          OnClick CLASS::OP_CLICK,;
  240.          Height          2.20,;
  241.          Text "*",;
  242.          ColorNormal "N/W"
  243.  
  244.    DEFINE PUSHBUTTON OPDIV OF THIS;
  245.        PROPERTY;
  246.          FontSize          9.00,;
  247.          Width          5.28,;
  248.          FontName "MS Serif",;
  249.          Top          7.43,;
  250.          Left         21.12,;
  251.          OnClick CLASS::OP_CLICK,;
  252.          Height          2.20,;
  253.          Text "/",;
  254.          ColorNormal "N/W"
  255.  
  256.    DEFINE PUSHBUTTON OPMINUS OF THIS;
  257.        PROPERTY;
  258.          FontSize          9.00,;
  259.          Width          5.28,;
  260.          FontName "MS Serif",;
  261.          Top          9.91,;
  262.          Left         21.12,;
  263.          OnClick CLASS::OP_CLICK,;
  264.          Height          2.20,;
  265.          Text "-",;
  266.          ColorNormal "N/W"
  267.  
  268.    DEFINE PUSHBUTTON CLEAR OF THIS;
  269.        PROPERTY;
  270.          FontSize          7.00,;
  271.          Width          5.28,;
  272.          FontName "Small Fonts",;
  273.          Top          2.47,;
  274.          Left         27.06,;
  275.          OnClick CLASS::CLEAR_CLICK,;
  276.          Height          2.20,;
  277.          Text "CE\C",;
  278.          FontBold .F.,;
  279.          ColorNormal "W*/R"
  280.  
  281.    DEFINE PUSHBUTTON OPEQUAL OF THIS;
  282.        PROPERTY;
  283.          FontSize          9.00,;
  284.          Width          5.28,;
  285.          FontName "MS Serif",;
  286.          Top          4.96,;
  287.          Left         27.06,;
  288.          OnClick CLASS::OP_CLICK,;
  289.          Height          2.20,;
  290.          Text "=",;
  291.          Default .T.,;
  292.          ColorNormal "N/W"
  293.  
  294.    DEFINE PUSHBUTTON OPPLUS OF THIS;
  295.        PROPERTY;
  296.          FontSize          9.00,;
  297.          Width          5.28,;
  298.          FontName "MS Serif",;
  299.          Top          7.43,;
  300.          Left         27.06,;
  301.          OnClick CLASS::OP_CLICK,;
  302.          Height          2.20,;
  303.          Text "+",;
  304.          ColorNormal "N/W"
  305.  
  306.    DEFINE PUSHBUTTON HEXDEC OF THIS;
  307.        PROPERTY;
  308.          FontSize          7.00,;
  309.          Width          5.28,;
  310.          FontName "Small Fonts",;
  311.          Top          9.91,;
  312.          Left         27.06,;
  313.          OnClick CLASS::CHANGEHEX,;
  314.          Height          2.20,;
  315.          Text "&Hex",;
  316.          FontBold .F.,;
  317.          ColorNormal "N/W"
  318.  
  319.    DEFINE PUSHBUTTON MADD OF THIS;
  320.        PROPERTY;
  321.          FontSize          7.00,;
  322.          Width          5.94,;
  323.          FontName "Small Fonts",;
  324.          Top          2.47,;
  325.          Left         33.66,;
  326.          OnClick CLASS::MEM_CLICK,;
  327.          Height          2.20,;
  328.          Text "&MAdd",;
  329.          FontBold .F.,;
  330.          ColorNormal "W+/B"
  331.  
  332.    DEFINE PUSHBUTTON MSUB OF THIS;
  333.        PROPERTY;
  334.          FontSize          7.00,;
  335.          Width          5.94,;
  336.          FontName "Small Fonts",;
  337.          Top          4.96,;
  338.          Left         33.66,;
  339.          OnClick CLASS::MEM_CLICK,;
  340.          Height          2.20,;
  341.          Text "M&Sub",;
  342.          FontBold .F.,;
  343.          ColorNormal "W+/B"
  344.  
  345.    DEFINE PUSHBUTTON MRCL OF THIS;
  346.        PROPERTY;
  347.          FontSize          7.00,;
  348.          Width          5.94,;
  349.          FontName "Small Fonts",;
  350.          Top          7.43,;
  351.          Left         33.66,;
  352.          OnClick CLASS::MRCL_PROC,;
  353.          Height          2.20,;
  354.          Text "M&Rcl",;
  355.          FontBold .F.,;
  356.          ColorNormal "W+/B"
  357.  
  358.    DEFINE PUSHBUTTON MCLR OF THIS;
  359.        PROPERTY;
  360.          FontSize          7.00,;
  361.          Width          5.94,;
  362.          FontName "Small Fonts",;
  363.          Top          9.91,;
  364.          Left         33.66,;
  365.          OnClick CLASS::MCLR_PROC,;
  366.          Height          2.20,;
  367.          Text "MClr",;
  368.          FontBold .F.,;
  369.          ColorNormal "W+/B"
  370.  
  371.    DEFINE PUSHBUTTON B_A OF THIS;
  372.        PROPERTY;
  373.          Width          5.28,;
  374.          Top         12.67,;
  375.          Left          3.30,;
  376.          OnClick CLASS::NUMERIC_CLICK,;
  377.          Height          2.20,;
  378.          Text "&A",;
  379.          ColorNormal "B+/W",;
  380.          Enabled .F.
  381.  
  382.    DEFINE PUSHBUTTON B_B OF THIS;
  383.        PROPERTY;
  384.          Width          5.28,;
  385.          Top         12.67,;
  386.          Left          9.24,;
  387.          OnClick CLASS::NUMERIC_CLICK,;
  388.          Height          2.20,;
  389.          Text "&B",;
  390.          ColorNormal "B+/W",;
  391.          Enabled .F.
  392.  
  393.    DEFINE PUSHBUTTON B_C OF THIS;
  394.        PROPERTY;
  395.          Width          5.28,;
  396.          Top         12.67,;
  397.          Left         15.18,;
  398.          OnClick CLASS::NUMERIC_CLICK,;
  399.          Height          2.20,;
  400.          Text "&C",;
  401.          ColorNormal "B+/W",;
  402.          Enabled .F.
  403.  
  404.    DEFINE PUSHBUTTON B_D OF THIS;
  405.        PROPERTY;
  406.          Width          5.28,;
  407.          Top         12.67,;
  408.          Left         21.12,;
  409.          OnClick CLASS::NUMERIC_CLICK,;
  410.          Height          2.20,;
  411.          Text "&D",;
  412.          ColorNormal "B+/W",;
  413.          Enabled .F.
  414.  
  415.    DEFINE PUSHBUTTON B_E OF THIS;
  416.        PROPERTY;
  417.          Width          5.28,;
  418.          Top         12.67,;
  419.          Left         27.06,;
  420.          OnClick CLASS::NUMERIC_CLICK,;
  421.          Height          2.20,;
  422.          Text "&E",;
  423.          ColorNormal "B+/W",;
  424.          Enabled .F.
  425.  
  426.    DEFINE PUSHBUTTON B_F OF THIS;
  427.        PROPERTY;
  428.          Width          5.28,;
  429.          Top         12.67,;
  430.          Left         32.99,;
  431.          OnClick CLASS::NUMERIC_CLICK,;
  432.          Height          2.20,;
  433.          Text "&F",;
  434.          ColorNormal "B+/W",;
  435.          Enabled .F.
  436.  
  437.    DEFINE ENTRYFIELD MEMORY OF THIS;
  438.        PROPERTY;
  439.          Value "                  ",;
  440.          FontSize         15.00,;
  441.          Width         40.26,;
  442.          FontName "Courier New",;
  443.          Top         15.41,;
  444.          Left          0.66,;
  445.          Height          1.66,;
  446.          Function "J",;
  447.          ColorNormal "W+/W",;
  448.          Border .T.,;
  449.          Enabled .F.
  450.  
  451.    ****************************************************************************
  452.    procedure OnOpen
  453.    ****************************************************************************
  454.  
  455.  
  456.    this.periodChar = setto("point")       && this is necessary for international
  457.    this.period.text = form.periodChar     && applications
  458.  
  459.    this.OpPlus.Doit = {|a,b|a+b}
  460.    this.OpMinus.Doit = {|a,b|a-b}
  461.    this.OpTimes.Doit = {|a,b|a*b}
  462.    this.OpDiv.Doit = {|a,b|a/b}
  463.    this.OpPower.Doit = {|a,b|a^b}
  464.    this.OpEqual.Doit = .f.
  465.    this.MAdd.Doit = {|a,b|a+b}
  466.    this.MSub.Doit = {|a,b|a-b}
  467.  
  468.    this.hex = .f.             && in hex or decimal mode
  469.    this.decPlaces = 0         && how many decimal places to use in calculation
  470.    this.mostDecPlaces = 0     && most decimal places in an operand for operation
  471.    this.beforePeriod = .t.    && add numbers before or after decimal pt.
  472.    this.lastKeyOperator = .f.
  473.    this.DefineBackgroundTexts()
  474.  
  475.    this.Clear.OnClick()
  476.    this.MClr.OnClick()
  477.  
  478.    ****************************************************************************
  479.    procedure OnGotFocus
  480.    ****************************************************************************
  481.    set decimals to form.decPlaces
  482.  
  483.    ****************************************************************************
  484.    procedure OnLostFocus
  485.    * Unset Enter key, so other forms can use it for their own purposes
  486.    ****************************************************************************
  487.    set decimals to
  488.  
  489.  
  490.    ****************************************************************************
  491.    procedure DefineBackgroundTexts
  492.  
  493.    * Define texts behind non-alphabetic characters, so the picks for the text
  494.    * will execute the onclick for these buttons, and button text doesn't
  495.    * look cluttered and strange.
  496.    ****************************************************************************
  497.    CLASS::DefineText(this.b1)
  498.    CLASS::DefineText(this.b2)
  499.    CLASS::DefineText(this.b3)
  500.    CLASS::DefineText(this.b4)
  501.    CLASS::DefineText(this.b5)
  502.    CLASS::DefineText(this.b6)
  503.    CLASS::DefineText(this.b7)
  504.    CLASS::DefineText(this.b8)
  505.    CLASS::DefineText(this.b9)
  506.    CLASS::DefineText(this.b0)
  507.    CLASS::DefineText(this.period)
  508.    CLASS::DefineText(this.opPower)
  509.    CLASS::DefineText(this.opTimes)
  510.    CLASS::DefineText(this.opDiv)
  511.    CLASS::DefineText(this.opMinus)
  512.    CLASS::DefineText(this.opPlus)
  513.    CLASS::DefineText(this.opEqual)
  514.  
  515.  
  516.    ****************************************************************************
  517.    procedure DefineText(button)
  518.  
  519.    * Define text to appear behind button.  This text will be before the button
  520.    * in the tabbing order
  521.    ****************************************************************************
  522.    private tName
  523.    tName = button.name + "Text"
  524.    define text &tName of this;
  525.       property;
  526.          top button.top,;
  527.          left button.left,;
  528.          text "&" + button.text,;
  529.          before button
  530.  
  531.    ****************************************************************************
  532.    procedure ChangeHex
  533.    ****************************************************************************
  534.    local value,memValue,dispFraction,memFraction
  535.  
  536.    * Get values in display and memory before changing hex indicator
  537.    value = NumVal(form.display.value, form.hex)
  538.    memValue = NumVal(form.memory.value, form.hex)
  539.    form.beforePeriod = .t.
  540.    set decimals to form.decPlaces
  541.    dispFraction = val(substr(form.display.value,;
  542.                              at(form.periodChar, form.display.value)))
  543.    memFraction = val(substr(form.memory.value,;
  544.                             at(form.periodChar, form.memory.value)))
  545.  
  546.    form.hex = .not. form.hex
  547.    this.text = iif(form.hex, "Dec", "&Hex")
  548.  
  549.    * Enable/disable hex letter digits
  550.    store form.hex to ;
  551.       form.B_A.enabled, form.B_B.enabled, form.B_C.enabled,;
  552.       form.B_D.enabled, form.B_E.enabled, form.B_F.enabled
  553.  
  554.    * Enable/disable keys not applicable to hex calculations
  555.    store .not. form.hex to ;
  556.       form.opPlusMinus.enabled, form.period.enabled
  557.  
  558.    if abs(value) > OVERFLOW
  559.       form.display.value = replicate("*",MAX_HEX_DIGITS)
  560.    else
  561.       form.display.value = CharVal(value + dispFraction, form.hex,;
  562.                                       form.decPlaces)
  563.    endif
  564.    if abs(memValue) > OVERFLOW
  565.       form.memory.value  = replicate("*",MAX_HEX_DIGITS)
  566.    else
  567.       form.memory.value = CharVal(memValue + memFraction, form.hex,;
  568.                                      form.decPlaces)
  569.    endif
  570.  
  571.    ****************************************************************************
  572.    procedure Numeric_Click
  573.    ****************************************************************************
  574.    local num
  575.    if form.lastKeyOperator
  576.       form.LastKeyOperator = .f.
  577.       form.beforePeriod = .t.
  578.       form.display.value = space(MAX_DEC_DIGITS - 1) + DisplayValue(this.text)
  579.    else
  580.       do case
  581.          case displayFull(form)
  582.             ??chr(7)
  583.          case form.beforePeriod
  584.             form.display.value = DisplayValue(form.display.value) +;
  585.                DisplayValue(this.text)
  586.          otherwise
  587.             form.display.value = AddAfterPeriod(form,DisplayValue(this.text))
  588.       endcase
  589.    endif
  590.    form.opEqual.SetFocus()
  591.  
  592.    ****************************************************************************
  593.    procedure Period_Click
  594.    ****************************************************************************
  595.    if form.beforePeriod .and. .not. form.hex
  596.       form.beforePeriod = .f.
  597.       form.decPlaces = 0
  598.       set decimals to 0
  599.       if form.lastKeyOperator
  600.          form.LastKeyOperator = .f.
  601.          form.display.value = space(MAX_DEC_DIGITS - 1) + form.periodChar
  602.       else
  603.          form.display.value = AddAfterPeriod(form,form.periodChar)
  604.       endif
  605.    endif
  606.  
  607.    ****************************************************************************
  608.    procedure Op_Click
  609.    ****************************************************************************
  610.    if form.LastKeyOperator .or. empty(form.lastOp)
  611.       form.lastValue = NumVal(form.display.value,form.hex)
  612.    else
  613.       set decimals to form.mostDecPlaces
  614.       form.lastValue = form.LastOp(form.lastValue, NumVal(form.display.value,;
  615.                                                       form.hex))
  616.       form.display.value = CharVal(form.lastValue, form.hex, form.mostDecPlaces)
  617.       form.decPlaces = 0
  618.       set decimals to 0
  619.    endif
  620.    form.beforePeriod = .t.
  621.    form.lastKeyOperator = .t.
  622.    form.LastOp = this.Doit
  623.  
  624.    ****************************************************************************
  625.    procedure Mem_Click
  626.    ****************************************************************************
  627.    local result
  628.  
  629.    result = this.Doit(NumVal(form.memory.value, form.hex),;
  630.       NumVal(form.display.value, form.hex))
  631.       form.memory.value = CharVal(result, form.hex, form.mostDecPlaces)
  632.  
  633.    ****************************************************************************
  634.    procedure MClr_Proc
  635.    ****************************************************************************
  636.    form.lastKeyOperator = .t.
  637.    form.memory.value = space(MAX_DEC_DIGITS - 1) + "0"
  638.  
  639.    ****************************************************************************
  640.    procedure MRcl_Proc
  641.    ****************************************************************************
  642.    if form.lastKeyOperator
  643.       form.LastKeyOperator = .f.
  644.       form.beforePeriod = .t.
  645.       form.lastValue = NumVal(form.display.value, form.hex)
  646.       form.display.value = form.memory.value
  647.    else
  648.       form.lastValue = NumVal(form.display.value, form.hex)
  649.       form.display.value = form.memory.value
  650.    endif
  651.  
  652.    ****************************************************************************
  653.    procedure Clear_Click
  654.    ****************************************************************************
  655.    form.lastOp = .f.
  656.    form.lastValue = 0
  657.    form.lastKeyOperator = .f.
  658.    form.decPlaces = 0
  659.    set decimals to 0
  660.    form.mostDecPlaces = 0
  661.    form.display.value = space(MAX_DEC_DIGITS - 1) + "0"
  662.    form.beforePeriod = .t.
  663.  
  664.    ****************************************************************************
  665.    procedure PlusMinus_Click
  666.    ****************************************************************************
  667.    local num
  668.    if .not. form.hex
  669.       num = NumVal(form.display.value, form.hex)
  670.       form.display.value = CharVal(num * -1, form.hex, form.mostDecPlaces)
  671.       form.LastKeyOperator = .t.
  672.    endif
  673.  
  674. ENDCLASS
  675.  
  676.  
  677.  
  678. *******************************************************************************
  679. function DisplayFull
  680. * Check if display already has MAX_DEC_DIGITS digits in it
  681. *******************************************************************************
  682. param calform
  683. local isFull,maxValueLen
  684. maxValueLen = iif(calform.hex, MAX_HEX_DIGITS,MAX_DEC_DIGITS)
  685. return substr(right(calform.display.value, maxValueLen), 1, 1) <> " "
  686.  
  687. *******************************************************************************
  688. function AddAfterPeriod(form, text)
  689. *******************************************************************************
  690. form.decPlaces = form.decPlaces + 1
  691. set decimals to form.decPlaces
  692. form.mostDecPlaces = max(form.decPlaces, form.mostDecPlaces)
  693. return DisplayValue(form.display.value) + text
  694.  
  695.  
  696. *******************************************************************************
  697. function DisplayValue(value)
  698. *  Display value without the pick character
  699. *******************************************************************************
  700. private num,pickLoc
  701. num = value
  702. pickLoc = at("&",num)
  703. do case
  704.    case pickLoc <> 0
  705.       num = stuff(num,pickLoc,1,"")
  706.    case right(num,2) = " 0"
  707.       num = space(MAX_DEC_DIGITS)
  708.    case left(num,1) = " "
  709.       num = substr(num,2)
  710. endcase
  711. return num
  712.  
  713.  
  714. *******************************************************************************
  715. function CharVal(num, hex, decPlaces)
  716. *******************************************************************************
  717. private string
  718. if hex
  719.    string = itoh(num)
  720.    string = space(MAX_DEC_DIGITS - len(string)) + string
  721. else
  722.    string = str(num, MAX_DEC_DIGITS, decPlaces)
  723. endif
  724. return string
  725.  
  726.  
  727. *******************************************************************************
  728. function NumVal(string,hex)
  729. *******************************************************************************
  730. private h,num,periodLoc,s
  731.  
  732. s = string
  733. if hex
  734.    h = htoi(string)
  735.    num = iif(h >= 2^31, bitxor(h,2^32), h)
  736. else
  737.    periodLoc = at(setto("point"),s)
  738.    if periodLoc <> 0
  739.       num = val(stuff(s,periodLoc,1,"."))
  740.    else
  741.       num = val(string)
  742.    endif
  743. endif
  744. return num
  745.  
  746.  
  747.  
  748.  
  749.  
  750.  
  751.  
  752.  
  753.  
  754.  
  755.  
  756.  
  757.  
  758.