C
C#2y ago
BambiAria

Problem with my project

So I need the 2nd panel event in the second attachment to call the method in the first attachment and use some of the variables ie timeOfFlight defined in the 3rd attachment really stuck with this would love some help
2 Replies
Kippachu
Kippachu2y ago
There are many ways of doing this, the simplest way would be to create a private field inside the class (outside the methods)
private double _timeOfFlight;
private double _timeOfFlight;
Change timeOfFlight to _timeOfFlight inside NoHorizontalAccelerationCalculation() method this way you are setting the value outside your method and so it becomes usable in others methods of the same class (private field) This means now you can do
private double _timeOfFlight;

private void GraphPanel_Click(object sender, EventArgs e)
{
NoHorizontalAccelerationCalculation() //This will set the _timeofFlight value
var drawingGraphLogic = DrawingGraphLogic(_timeOfFlight, 1, 1) //here you use the method from your first attachment, using the timeOfFlight value set inside NoHorizontalAccelerationCalculation() ie third attachment
[...] //continue your code
}
private double _timeOfFlight;

private void GraphPanel_Click(object sender, EventArgs e)
{
NoHorizontalAccelerationCalculation() //This will set the _timeofFlight value
var drawingGraphLogic = DrawingGraphLogic(_timeOfFlight, 1, 1) //here you use the method from your first attachment, using the timeOfFlight value set inside NoHorizontalAccelerationCalculation() ie third attachment
[...] //continue your code
}
Note : This will work but is totally not the best way to do, you'll have to change this behaviour later., just gave you an easy solution in many solutions. Is it ok for you ?
BambiAria
BambiAriaOP2y ago
yep that has worked fine thank you
Want results from more Discord servers?
Add your server