Click here to Skip to main content
15,028,757 members
Home / Discussions / C#
   

C#

 
GeneralRe: Passing parameter from one page to another Pin
Gerry Schmitz28-Jun-21 8:02
mveGerry Schmitz28-Jun-21 8:02 
GeneralRe: Passing parameter from one page to another Pin
Richard Andrew x6428-Jun-21 14:23
professionalRichard Andrew x6428-Jun-21 14:23 
GeneralRe: Passing parameter from one page to another Pin
Richard MacCutchan28-Jun-21 21:13
mveRichard MacCutchan28-Jun-21 21:13 
GeneralRe: Passing parameter from one page to another Pin
Alex Dunlop29-Jun-21 4:53
MemberAlex Dunlop29-Jun-21 4:53 
GeneralRe: Passing parameter from one page to another Pin
Richard MacCutchan29-Jun-21 5:44
mveRichard MacCutchan29-Jun-21 5:44 
QuestionCreate the same but in windows form C# Pin
Luis M. Rojas25-Jun-21 6:16
MemberLuis M. Rojas25-Jun-21 6:16 
AnswerRe: Create the same but in windows form C# Pin
OriginalGriff25-Jun-21 6:23
mveOriginalGriff25-Jun-21 6:23 
QuestionDifficulty adding code to reject non numeric user inputs Pin
Member 1524886723-Jun-21 5:58
MemberMember 1524886723-Jun-21 5:58 
Hello everyone,

Having a difficult time adding code to reject non numeric user inputs into text boxes. Can someone please view the following code and give me a path forward? Anything I've tried has resulted in errors.

<
private void btnCalculate_Click(object sender, EventArgs e)
      {
          // Validates user inputted data and calculates the value at the end of each year
          // displayed in multiline textbox
          double dblPresentValue = 0;
          double dblSalvageValue = 0;
          int intYearsOfDepreciation = 0;
          int intCounter = 0;
          string strDisplay = "";

          // Clear any text already in display
          txtDisplay.Text = "";

          // Get values from text boxes
          dblPresentValue = Convert.ToDouble(txtPresentValue.Text);
          dblSalvageValue = Convert.ToDouble(txtSalvageValue.Text);
          intYearsOfDepreciation = Convert.ToInt32(txtYearsOfDepreciation.Text);

          // Validate user entry
          if (dblPresentValue < 1 | dblPresentValue > 1000000)
          {
              MessageBox.Show("Present value must be between $1 and $1,000,000");
              txtPresentValue.Select(); //selects defective input text box
              txtPresentValue.SelectAll();
          }
          else if (dblSalvageValue > dblPresentValue)
          {
              MessageBox.Show("Salvage value cannot be greater than Present Value");
              txtSalvageValue.Select(); //selects defective input text box
              txtSalvageValue.SelectAll();
          }
          else if (intYearsOfDepreciation < 0 | intYearsOfDepreciation > 25)
          {
              MessageBox.Show("Years of Depreciation must be in 1 - 25 range");
              txtYearsOfDepreciation.Select(); //selects defective input text box
              txtYearsOfDepreciation.SelectAll();
          }
          else
          {
              // set up column headers in text display
              strDisplay = "Year      Asset Value\r\n-------      ---------------";
              // pre-test loop + calcuate + display as currency
              double period = (dblPresentValue - dblSalvageValue)/intYearsOfDepreciation;

              int curYear = DateTime.Now.Year;
              while (intCounter < intYearsOfDepreciation) //loop control statement
              {
                  strDisplay += "\r\n"+ curYear.ToString() + ": " + dblPresentValue.ToString("C2");
                  intCounter = intCounter + 1;
                  dblPresentValue -= period;
                  curYear++;
              }
              txtDisplay.Text = strDisplay;

          }


      }

AnswerRe: Difficulty adding code to reject non numeric user inputs Pin
OriginalGriff23-Jun-21 6:08
mveOriginalGriff23-Jun-21 6:08 
GeneralRe: Difficulty adding code to reject non numeric user inputs Pin
Member 1524886723-Jun-21 7:15
MemberMember 1524886723-Jun-21 7:15 
GeneralRe: Difficulty adding code to reject non numeric user inputs Pin
OriginalGriff23-Jun-21 7:32
mveOriginalGriff23-Jun-21 7:32 
GeneralLimitless printing Pin
Member 1419221622-Jun-21 1:21
MemberMember 1419221622-Jun-21 1:21 
GeneralRe: Limitless printing Pin
OriginalGriff22-Jun-21 2:26
mveOriginalGriff22-Jun-21 2:26 
GeneralRe: Limitless printing Pin
jsc4222-Jun-21 3:04
professionaljsc4222-Jun-21 3:04 
GeneralRe: Limitless printing Pin
Gerry Schmitz22-Jun-21 6:57
mveGerry Schmitz22-Jun-21 6:57 
QuestionC# graph/diagram showing executing tasks vs time, that scales well with large data sets? Pin
arnold_w21-Jun-21 21:23
Memberarnold_w21-Jun-21 21:23 
AnswerRe: C# graph/diagram showing executing tasks vs time, that scales well with large data sets? Pin
Gerry Schmitz22-Jun-21 6:43
mveGerry Schmitz22-Jun-21 6:43 
AnswerRe: C# graph/diagram showing executing tasks vs time, that scales well with large data sets? Pin
BillWoodruff22-Jun-21 19:02
mveBillWoodruff22-Jun-21 19:02 
GeneralRe: C# graph/diagram showing executing tasks vs time, that scales well with large data sets? Pin
Gerry Schmitz23-Jun-21 7:26
mveGerry Schmitz23-Jun-21 7:26 
GeneralRe: C# graph/diagram showing executing tasks vs time, that scales well with large data sets? Pin
BillWoodruff23-Jun-21 23:27
mveBillWoodruff23-Jun-21 23:27 
GeneralRe: C# graph/diagram showing executing tasks vs time, that scales well with large data sets? Pin
Gerry Schmitz24-Jun-21 6:27
mveGerry Schmitz24-Jun-21 6:27 
QuestionLinking forms Pin
Member 1524886721-Jun-21 12:15
MemberMember 1524886721-Jun-21 12:15 
AnswerRe: Linking forms Pin
Richard Andrew x6421-Jun-21 13:22
professionalRichard Andrew x6421-Jun-21 13:22 
GeneralRe: Linking forms Pin
Member 1524886721-Jun-21 13:31
MemberMember 1524886721-Jun-21 13:31 
GeneralRe: Linking forms Pin
Richard Andrew x6421-Jun-21 13:43
professionalRichard Andrew x6421-Jun-21 13:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.