Question: I'm learning how to make and program forms in visual studio and have a very simple task. I need to take a textBox and apply
I'm learning how to make and program forms in visual studio and have a very simple task. I need to take a textBox and apply its value to a trackbar in order to manually set it. I made a code that takes the double values of the textbox then sets it to an integer for the trackbar, then takes the value again and converts it to a float value for a dataset not present in the snippets provided. It all works, but I was told that I need to remove the global variables. One of the methods to make this work without the global variables is to "update the method to take a string argument and return an integer." But I'm not sure how I can get this to work without the global variables.
Also, keep in mind, this is just a snippet of the entire code, as I'm only including what is relevant, which is why there is a line involving trackBar1, but no private void for said trackBar.
private string converterString;
private int doubIntConvert;
private float set;
private void doubleToInteger()
{
try
{
double converter = double.Parse(converterString);
{
if (converter >= 1)
{
converter = 1;
}
if (converter <= 0)
{
converter = 0;
}
if (converter >= 0 || converter <= 1)
{
doubIntConvert = Convert.ToInt32(converter * 100);
set = (doubIntConvert / 100f);
}
}
}
catch (Exception ex)
{
LogError("Exception caught during string input: " + ex.Message);
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
converterString = textBox1.Text;
doubleToInteger();
trackBar1.Value = doubIntConvert;
outsideData.something.yaddaYadda = set;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
