Skip to main content
added 88 characters in body
Source Link
Gilad Green
  • 37.1k
  • 7
  • 65
  • 97

value is defined in the scope of the button3_Click and thus not accessible for the button2_Click. Put it as a variable of the class:

private int _minValue = 50;
private int _maxValue = 100;

private float value_value = 0;_maxValue;

private void button3_Click(object sender, EventArgs e)
{
    Random b = new Random();
    float value_value = b.Next(50_minValue, 100_maxValue);
}

private void button2_Click(object sender, EventArgs e)
{
    if (value_value < MinValue_minValue)
    {
        textBox18.Text = ("warning");
        textBox18.ForeColor = Color.White;
        textBox18.BackColor = Color.Red;
    }
}

value is defined in the scope of the button3_Click and thus not accessible for the button2_Click. Put it as a variable of the class:

private float value = 0;
private void button3_Click(object sender, EventArgs e)
{
    Random b = new Random();
    float value = b.Next(50, 100);
}

private void button2_Click(object sender, EventArgs e)
{
    if (value < MinValue)
    {
        textBox18.Text = ("warning");
        textBox18.ForeColor = Color.White;
        textBox18.BackColor = Color.Red;
    }
}

value is defined in the scope of the button3_Click and thus not accessible for the button2_Click. Put it as a variable of the class:

private int _minValue = 50;
private int _maxValue = 100;

private float _value = _maxValue;

private void button3_Click(object sender, EventArgs e)
{
    Random b = new Random();
    _value = b.Next(_minValue, _maxValue);
}

private void button2_Click(object sender, EventArgs e)
{
    if (_value < _minValue)
    {
        textBox18.Text = ("warning");
        textBox18.ForeColor = Color.White;
        textBox18.BackColor = Color.Red;
    }
}
Source Link
Gilad Green
  • 37.1k
  • 7
  • 65
  • 97

value is defined in the scope of the button3_Click and thus not accessible for the button2_Click. Put it as a variable of the class:

private float value = 0;
private void button3_Click(object sender, EventArgs e)
{
    Random b = new Random();
    float value = b.Next(50, 100);
}

private void button2_Click(object sender, EventArgs e)
{
    if (value < MinValue)
    {
        textBox18.Text = ("warning");
        textBox18.ForeColor = Color.White;
        textBox18.BackColor = Color.Red;
    }
}