0

The error I receive is as follows: There is no argument given that corresponds to the required formal parameter 'bloodPressureSystolicLevel' of 'VitalsForm.SetOverallHypertensionLevel(int, int)'. The error actually appears on the line where I call the method, SetOverallHypertensionLevel();

Calling the method:

 private void picSubmitVitals_Click(object sender, EventArgs e) { SetOverallHypertensionLevel(); } 

Method:

 private void SetOverallHypertensionLevel(int bloodPressureSystolicLevel, int bloodPressureDiastolicLevel) { bloodPressureSystolicLevel = Convert.ToInt32(txtSystolic); bloodPressureDiastolicLevel = Convert.ToInt32(txtDiastolic); if ((bloodPressureSystolicLevel / 200) > (bloodPressureDiastolicLevel / 133)) { if (bloodPressureSystolicLevel >= 160) { lblHyperStage2.ForeColor = colorSchemeIssue; } else if (bloodPressureSystolicLevel >= 140) { lblHyperStage1.ForeColor = colorSchemeIssue; } else if (bloodPressureSystolicLevel >= 120) { lblHyperPre.ForeColor = colorSchemeWarning; } else { lblHyperNormal.ForeColor = colorSchemeNormal; } } else { if (bloodPressureDiastolicLevel >= 100) { lblHyperStage2.ForeColor = colorSchemeIssue; } else if (bloodPressureDiastolicLevel >= 90) { lblHyperStage1.ForeColor = colorSchemeIssue; } else if (bloodPressureSystolicLevel >= 80) { lblHyperPre.ForeColor = colorSchemeWarning; } else { lblHyperNormal.ForeColor = colorSchemeNormal; } 

Why isn't it recognizing the use of the parameters? Any help is appreciated.

7
  • Could you show the code where you call this method? Commented May 7, 2018 at 22:31
  • How are you calling SetOverallHypertensionLevel? Likely it's without a parameter. Commented May 7, 2018 at 22:31
  • In your question where you say " 'VitalsForm.SetOverallHypertensionLevel(int, int)' " if that is the code you are using to call the method, then it looks like you are not passing in values, but instead you are placing type int where variables of type int belong Commented May 7, 2018 at 22:35
  • I added it above! Commented May 7, 2018 at 22:36
  • Thank you! Could you provide an example? Clearly I'm pretty new to this. Commented May 7, 2018 at 22:42

2 Answers 2

2
private void SetOverallHypertensionLevel(int bloodPressureSystolicLevel, int bloodPressureDiastolicLevel) { bloodPressureSystolicLevel = Convert.ToInt32(txtSystolic); bloodPressureDiastolicLevel = Convert.ToInt32(txtDiastolic); 

should likely be converted to:

private void SetOverallHypertensionLevel() { var bloodPressureSystolicLevel = Convert.ToInt32(txtSystolic); var bloodPressureDiastolicLevel = Convert.ToInt32(txtDiastolic); 

since it looks like you want variables not parameters.

If you do that your SetOverallHypertensionLevel(); call will work.

Sign up to request clarification or add additional context in comments.

3 Comments

That does work to get rid of the error on the call, but then my if statements don't work.
@Jen - Your if statement probably doesn't work as intended because you are dividing an int by an int. That will produce truncated int results. Divide by 200.0 and 133.0 and that will force the calcuations to be floating point, and thus more comparable.
@Jen The way StackOverflow works is that you should ask one question per post. Once that question is answered (Why isn't it recognizing the use of the parameters?) you should ask a separate question if you have a different question (like the unhandled exception).
1

When you call your method

SetOverallHypertensionLevel(); 

you need to pass in the required arguments for the parameters defined in your method signature.

SetOverallHypertensionLevel(int bloodPressureSystolicLevel, int bloodPressureDiastolicLevel) 

So an example of a correct call of that method would be:

SetOverallHypertensionLevel(1,1); 

You just need to provide the int values required by your method.

7 Comments

In this case the values will vary depending on user input, so I can't hard code integers (see the Convert and If / else-if statements above). If I use SetOverallHypertensionLevel(int bloodPressureSystolicLevel, int bloodPressureDiastolicLevel); it won't work, or if I try SetOverallHypertensionLevel(bloodPressureSystolicLevel, bloodPressureDiastolicLevel);
Or, remove the two arguments from the method signature, since the values for them are populated in the first two lines of the method (which would overwrite passed in values anyway).
@hatchet, that gets rid of the parameter error, but then the populated values run into an unhandled exception.
mjwills answer is the correct answer. If you follow that, then the next possible problem is whether txtSystolic and txtDiastolic are declared and populated properly elsewhere, but since you didn't include that code, it's hard to say. That would be a separate question.
@mjwills, the method still wasn't working, so it didn't solve my problem. I have made those changes, though. hatchet, I do have those declared and populated elsewhere, so I'll work on moving them to a broader class. Thank you!
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.