Example #1
0
        private void OnUndoPressed(object sender, EventArgs e)
        {
            sbInBound.Clear();
            InBound.Clear();
            this.FindByName <Label>("Input").Text = string.Empty;


            Fraction_class workFraction = new Fraction_class();

            workFraction.SetValueTo(Accumulator);

            Accumulator.SetValueTo(UndoAccum);
            sbAccumulator.Clear();
            if (displayToggle == DisplayToggle.floating)
            {
                sbAccumulator.Append(Accumulator.ToDisplayFloat(" "));
            }
            else
            {
                sbAccumulator.Append(Accumulator.ToDisplayFraction(" "));
            }

            this.FindByName <Label>("Result").Text = sbAccumulator.ToString();

            lastOperator = ' ';

            UndoAccum.SetValueTo(workFraction); // next undo will circle back
        }
Example #2
0
        /// <summary>
        /// OnMemoryLoadPressed() - Initially the M+ key ready to receive data from Accumulator.
        ///                       - Stores the data until M- or MC key is hit.
        ///                       - M+ key puts Accumulator data in memory.
        ///                       - M- moves memory to InBound, and clears memory.
        ///
        /// </summary>
        /// <remarks>
        ///   Side effects - MemButton keytop toggles between M+ and M-.
        ///                - if initially M+ Memory is set to Accumulator and toggles to M-.
        ///                - if initially M- InBound is set to Memory, Memory is cleared, and toggles to M+.
        /// </remarks>
        private void OnMemoryLoadPressed(object sender, EventArgs e)
        {
            string keyToggle = this.FindByName <Button>("MemButton").Text;

            if (keyToggle == "M+")
            {
                MemorySave.SetValueTo(Accumulator);
                this.FindByName <Button>("MemButton").Text = "M-";
            }
            else
            {
                InBound.SetValueTo(MemorySave);
                MemorySave.Clear();
                this.FindByName <Button>("MemButton").Text = "M+";
                sbInBound.Clear();
                if (displayToggle == DisplayToggle.floating)
                {
                    sbInBound.Append(InBound.ToDisplayFloat(" "));
                }
                else
                {
                    sbInBound.Append(InBound.ToDisplayFraction(" "));
                }

                this.FindByName <Label>("Input").Text = sbInBound.ToString();
            }
        }
Example #3
0
        // try/catch?
        private void OnOperatorPressed(object sender, EventArgs e)
        {
            // procedurally there's no input yet, maybe better way to do this
            if (this.FindByName <Label>("Input").Text is null || this.FindByName <Label>("Input").Text.Trim().Length == 0)
            {
                lastOperator = (sender as Button).Text.ToCharArray()[0];
                return;
            }

            //
            if (InBound.Parse(sbInBound.ToString()) == false)
            {
                this.FindByName <Label>("Input").Text = String.Empty;   // nasty error response.
                sbInBound.Clear();
                return;
            }
            sbInBound.Clear();
            this.FindByName <Label>("Input").Text = sbInBound.ToString();

            UndoAccum.SetValueTo(Accumulator);

            switch (lastOperator)
            {
            case '+':
                Accumulator.Add(InBound);
                break;

            case '-':
                Accumulator.Subtract(InBound);
                break;

            case '/':
                Accumulator.DivideBy(InBound);
                break;

            case '*':
                Accumulator.MultiplyBy(InBound);
                break;

            case '=':
                if (Accumulator.ToDisplayFloat("0") == "0")
                {
                    Accumulator.SetValueTo(InBound);
                }
                break;

            case '%':
                Accumulator.Modulus(InBound);
                break;

            default:
                //-- Accumulator.SetValueTo(InBound);
                break;
            }
            ;

            lastOperator = (sender as Button).Text.ToCharArray()[0];

            sbAccumulator.Clear();  // whats the best way to set stringbuilder?
            if (displayToggle == DisplayToggle.fractional)
            {
                sbAccumulator.Append(Accumulator.ToDisplayFraction());
            }
            else
            {
                sbAccumulator.Append(Accumulator.ToDisplayFloat());
            }

            this.FindByName <Label>("Result").Text     = sbAccumulator.ToString();
            this.FindByName <Label>("Result").FontSize =
                shrinkLabel(this.FindByName <Label>("Result"), 16, 30, sbAccumulator.ToString());
        }