Visual Studio-Code Help!

private: System::Void checkBox1_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {

double maxValue;
double minValue;


if(checkBox1->CheckState == CheckState::Checked)
{


Error 1: -----> maxValue = (double)this->chart2->Series["Series1"]->Points->FindMaxByValue;
Error2:-----> minValue = (double)this->chart2->Series["Series1"]->Points->FindMinByValue;

textBox1->Text = maxValue.ToString();
textBox6->Text = minValue.ToString();
}
else if(checkBox1->CheckState == CheckState::Unchecked)
{

this->chart2->ChartAreas[0]->AxisY->Minimum = 5;
this->chart2->ChartAreas[0]->AxisY->Maximum = 15;

}


}

This is my code, and I am getting two errors which is:
error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'double'
error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'double'
Can anyone help??
Last edited on
You haven't given us the line numbers of the lines that are generating the errors.

My guess is that FindMaxByValue and FindMinByValue are the names of functions that you're trying to call. However, you're not calling them, because you're just using the names of those functions without any parentheses.

I put where the errors are. I found FindMaxByValue and FindMinByValue, in the library of Visual Studio of Windows Application Form.
Yes, but the syntax you're using on those lines is not the way you call a function.

If you don't understand what I'm saying, you should go back to your textbook and re-read the section on calling functions.
I understand what you are saying, I guess I am confused how to use the function in this syntax.
Can you give an example?
There's nothing special about it. You call them just like any other function in C/C++.

You're already doing it right elsewhere in your code.
Okay, thanks. I will look at it and at least I know what the problem is now.
Last edited on
I put a parentheses at the end to make it a function, but that still doesn't make it work.
My errors are:
error C2440: 'type cast' : cannot convert from 'System::Windows::Forms::DataVisualization::Charting::DataPoint ^' to 'double'
fatal error C1903: unable to recover from previous error(s); stopping compilation
Last edited on
What is the return type of those functions?

Is that return type one which can be converted to a double?
private: System::Void checkBox1_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {

DataPoint^ maxValue;
DataPoint^ minValue;
DataPoint^ maxValue1;
DataPoint^ minValue1;
DataPoint^ maxValue2;
DataPoint^ minValue2;

if(checkBox1->CheckState == CheckState::Checked)
{

maxValue = this->chart2->Series["Series1"]->Points->FindMaxByValue("Y1", 0);
minValue = this->chart2->Series["Series1"]->Points->FindMinByValue("Y1", 0);

maxValue1 = this->chart1->Series["Series1"]->Points->FindMaxByValue("Y1", 0);
minValue1 = this->chart1->Series["Series1"]->Points->FindMinByValue("Y1", 0);

maxValue2 = this->chart3->Series["Series1"]->Points->FindMaxByValue("Y1", 0);
minValue2 = this->chart3->Series["Series1"]->Points->FindMinByValue("Y1", 0);



this->chart2->ChartAreas[0]->AxisY->Maximum = maxValue;
this->chart2->ChartAreas[0]->AxisY->Minimum = minValue;

textBox1->Text = maxValue->YValues[0].ToString();
textBox6->Text = minValue->YValues[0].ToString();
textBox7->Text = maxValue1->YValues[0].ToString();
textBox8->Text = minValue1->YValues[0].ToString();
textBox9->Text = maxValue2->YValues[0].ToString();
textBox10->Text = minValue2->YValues[0].ToString();

}
else if(checkBox1->CheckState == CheckState::Unchecked)
{

this->chart2->ChartAreas[0]->AxisY->Minimum = 5;
this->chart2->ChartAreas[0]->AxisY->Maximum = 15;

this->chart1->ChartAreas[0]->AxisY->Minimum = 5;
this->chart1->ChartAreas[0]->AxisY->Maximum = 15;

this->chart3->ChartAreas[0]->AxisY->Minimum = 5;
this->chart3->ChartAreas[0]->AxisY->Maximum = 15;

//this->chart3->ChartAreas[0]->AxisY->Minimum;
//this->chart3->ChartAreas[0]->AxisY->Maximum;




}


}

I found the problem. A datapoint needed to be added in. It works perfectly now.
I found the problem. A datapoint needed to be added in. It works perfectly now.

More accurately: you changed the types of maxValue and minValue so that they could store the objects that were returned from FindMaxByValue and FindMinByValue.

The take-home lesson here is: when using a third-party function, look at the documentation to find out how to use it correctly.

Glad it's working now :)
Last edited on
Topic archived. No new replies allowed.