public static DividendPrediction[] ConvertStringArray(string[] _predictions, string[] _amounts, int _length) { for (int i = 0; i < _length; i++) { if (_predictions[i] == "") { _predictions[i] = "0"; } if (_amounts[i] == "") { _amounts[i] = "0"; } } DividendPrediction[] _predicts = new DividendPrediction[_length]; for (int i = 0; i < _length; i++) { try { _predicts[i] = new DividendPrediction( (float)Convert.ToDecimal(_predictions[i]), (float)Convert.ToDecimal(_amounts[i]) ); } catch { return(null); } } return(_predicts); }
void TextChanged(object sender, EventArgs e) { DividendPrediction[] _dividends = new DividendPrediction[txtb_Amount.Lines.Length]; try { for (int i = 0; i < _dividends.Length; i++) { _dividends[i] = new DividendPrediction(Convert.ToSingle(txtb_Prediction.Lines[i]), Convert.ToSingle(txtb_Amount.Lines[i])); } //MainForm.Instance.dividends = _dividends; } catch (Exception exc) { //MessageBox.Show(exc.Message); used for bug fixing }; }
void Txtb_TextChanged(object sender, EventArgs e) { int shortest = (txtb_Prediction.Lines.Length < txtb_Amount.Lines.Length)? txtb_Prediction.Lines.Length : txtb_Amount.Lines.Length; DividendPrediction[] _dividends = DividendPrediction.ConvertStringArray(txtb_Prediction.Lines, txtb_Amount.Lines, shortest); if (_dividends == null) { MessageBox.Show("Not in correct format"); return; } if (same) { MainForm.Instance.dividendPrediction = Calculation.GetBounds(_dividends); } else { if (combob_Date.SelectedIndex == -1) { MessageBox.Show("Select a date or same"); return; } predictions[combob_Date.SelectedIndex] = Calculation.GetBounds(_dividends); MainForm.Instance.dividendPrediction = Calculation.GetAverageBounds(predictions); } if (MainForm.Instance.dividendPrediction != null) { float[] _bounds = MainForm.Instance.dividendPrediction; for (int i = 0; i < _bounds.Length; i++) { _bounds[i] = (float)Math.Round(_bounds[i], 3); } lbl_Upper.Text = string.Format("Upper: {0}", _bounds[2]); lbl_Median.Text = string.Format("Median: {0}", _bounds[1]); lbl_Lower.Text = string.Format("Lower: {0}", _bounds[0]); } }