//Sumbutton private void buttonSum_Click(object sender, EventArgs e) { removeDecimal(); //Methods already gone through first update the calculationtextbox so all info //is brought to the listbox CalcTextboxUpdate(CI.selectedcalcmethod); //The old arithmetic sign is removed from the Calculationstring before adding it to the listbox textBoxCalculations.Text = textBoxCalculations.Text.Remove(textBoxCalculations.Text.Length - 1); //Then make sure the current calculation is carried out and if everything is ok... if (calculate(CI.selectedcalcmethod)) { //... An item is added as a historyrecord object unless there have been an error in calculations listBoxHistory.Items.Add(new HistoryRecord(textBoxCalculations.Text, double.Parse(textBoxOutput.Text, fmt))); } //This is basically a C button event but to avoid getting a canceling event i the logg //I reset it piece by piece #region CHANGE`S 1. //Old code, Would return 0 to the Output textbox after sum //textBoxOutput.Text = "0"; //textBoxCalculations.Text = null; //CI.Creset(); //New code, Let's the value of the outputbox retain it's value to the next calculation textBoxCalculations.Text = null; CI.Creset(); CI.currentSum = double.Parse(textBoxOutput.Text, fmt); #endregion }
}/// <summary> /// 2.Addition 3.Substraction 4.Multiplikation 5.Division /// </summary> /// <param name="switchis">Choose between the Arithmetics</param> /// <param name="inputdata">The number to count with</param> /// <returns>Sets CI.currentsum to the calculated value</returns> public void Calculations(int switchis, double inputdata) { double returner = inputdata; switch (switchis) { //Addition case 2: { returner = double.Parse(Methods[(switchis)].Invoke(null, new object[] { CI.currentSum, inputdata }).ToString()); break; } //Substraction case 3: { returner = double.Parse(Methods[(switchis)].Invoke(null, new object[] { CI.currentSum, inputdata }).ToString()); break; } //Multiplication case 4: { returner = double.Parse(Methods[(switchis)].Invoke(null, new object[] { CI.currentSum, inputdata }).ToString()); break; } //Division case 5: { if (inputdata == 0) { //old solution before a more serious one #region Old Joke //This is a joke. Could be set to anything. in any case dividing by 0 is an infinity //soooo... ... //returner = 1337; #endregion #region CHANGE`S 2 //Added null check. //Fire an event if (DivideByZero != null) { DivideByZero(); } #endregion //Begin reseting calculation CI.Creset(); } else { returner = double.Parse(Methods[(switchis)].Invoke(null, new object[] { CI.currentSum, inputdata }).ToString()); } break; } default: { break; } } //If the answer is less then 0 throw the Negative event with returner as parameter if (returner < 0) { #region CHANGE`S 3 //Added Nullcheck if (Negative != null) { Negative(returner); } #endregion } //finaly set CI.currentsum to the value CI.currentSum = returner; }