-1

I'm supposed to make a math practice program for kids. They should be able to choose 1 operation and the amount of digits (1, 2 or 3 digit) the numbers will have. It then has to out put 10 random questions according to the selection made by the kid, then once they have completed the quiz, it should display their results and which questions they got wrong.

I have two selections being made on form1, operations and # of digits, which are assigned numbers (1. (*) 2. (/) 3. (+) 4. (-)). All i need to do is communicate the operation number and # of digits to form2, where the questions will be generated and displayed.

Here's my code for form1 so far:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FinalProject
{
public partial class Form1 : Form
{
   public static int operation = 0;
    public static int digits = 0;

    public Form1()
    {
        InitializeComponent();
    }
    // this is to make sure only one box is checked for both selections. Starts here
    private void label1_Click(object sender, EventArgs e)
    {

    }

    private void button2_Click(object sender, EventArgs e)
    {

    }

    private void MulCB_CheckedChanged(object sender, EventArgs e)
    {


        if ( MulCB.Checked == true)
        {
            operation = 1;
            DivCB.Checked = false;
            AddCB.Checked = false;
            SubCB.Checked = false;
        }
    }

    private void DivCB_CheckedChanged(object sender, EventArgs e)
    {
        if (DivCB.Checked == true)
        {
            operation = 2;
            MulCB.Checked = false;
            AddCB.Checked = false;
            SubCB.Checked = false;
        }
    }

    private void AddCB_CheckedChanged(object sender, EventArgs e)
    {
        if (AddCB.Checked == true)
        {
            operation = 3;
            DivCB.Checked = false;
            SubCB.Checked = false;
            MulCB.Checked = false;
        }
    }

    private void SubCB_CheckedChanged(object sender, EventArgs e)
    {
        if (SubCB.Checked == true)
        {
            operation = 4;
            DivCB.Checked = false;
            AddCB.Checked = false;
            MulCB.Checked = false;
        }
    }

    private void oneDCB_CheckedChanged(object sender, EventArgs e)
    {
        if(oneDCB.Checked == true)
        {
            digits = 1;
            twoDCB.Checked = false;
            threeDCB.Checked = false;
        }
    }

    private void twoDCB_CheckedChanged(object sender, EventArgs e)
    {
        if ( twoDCB.Checked == true)
        {
            digits = 2;
            oneDCB.Checked = false;
            threeDCB.Checked = false;
        }
    }

    private void threeDCB_CheckedChanged(object sender, EventArgs e)
    {
        if (threeDCB.Checked == true)
        {
            digits = 3;
            oneDCB.Checked = false;
            twoDCB.Checked = false;
        }
    }
    private void button8_Click(object sender, EventArgs e)
    {
        // operations: 1. (*) 2. (/) 3. (+) 4. (-)
        // digits are as number indicates.



        // Second window popup.
        Form2 settingsForm = new Form2();
        settingsForm.Show();
    }
}
}

Here's form2, naked pretty much.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FinalProject
{

public partial class Form2 : Form
{


    public Form2()
    {
        InitializeComponent();
    }

    private void FinishedBtn_Click(object sender, EventArgs e)
    {


    }
}

}

Sal
  • 59
  • 1
  • 1
  • 7
  • Hi Sal! Can you please edit your question to: 1. contain much less code, 2. say what you have tried, what has and has not worked, and 3. say specifically what information you would like to send/receive and what specifically you need help with? Also, I think that @DourHighArch is probably right that this question is a duplicate. – Max von Hippel May 07 '17 at 20:49
  • If you'd like you can head over to the [help center](https://stackoverflow.com/help/how-to-ask) for tips on how to ask a more appropriate question for SO. Good luck, and thanks! – Max von Hippel May 07 '17 at 20:50
  • You put the variables in the wrong Form. `public static int operation = 0; public static int digits = 0;` are supposed to be in form2, not 1. They are Properties of the Form that can be set after invoking a new instance if it (like `Form2 settingsForm = new Form2();` – rudib May 07 '17 at 20:56
  • @rudib Okay I put the variables in form2 now, im confused as to what you mean by "invoking new instance". If form 2 is the "subscriber" and form 1 is the "publisher", what do i put in form1. This isn't URGENT, but its due in 4 days. – Sal May 07 '17 at 21:17
  • settingsForm is "the new instance". Sorry for confusing you. Reference: https://learn.microsoft.com/en-us/dotnet/articles/csharp/language-reference/keywords/new-operator – rudib May 07 '17 at 21:22

1 Answers1

0

This might work. There are comments in the code.

The workflow is creating a new instance of the class Form2 and setting two public variables. Public means that they can be accessed from outside of the class (see here, if you want). Then the method Show() is called and the Form appears. In the Form2 code, the public variables now have the values previously specified and can be used.

Form1:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FinalProject
{
public partial class Form1 : Form
{    
    public Form1()
    {
        InitializeComponent();
    }
    // this is to make sure only one box is checked for both selections. Starts here
    private void label1_Click(object sender, EventArgs e)
    {

    }

    private void button2_Click(object sender, EventArgs e)
    {

    }

    private void MulCB_CheckedChanged(object sender, EventArgs e)
    {


        if ( MulCB.Checked == true)
        {
            operation = 1;
            DivCB.Checked = false;
            AddCB.Checked = false;
            SubCB.Checked = false;
        }
    }

    private void DivCB_CheckedChanged(object sender, EventArgs e)
    {
        if (DivCB.Checked == true)
        {
            operation = 2;
            MulCB.Checked = false;
            AddCB.Checked = false;
            SubCB.Checked = false;
        }
    }

    private void AddCB_CheckedChanged(object sender, EventArgs e)
    {
        if (AddCB.Checked == true)
        {
            operation = 3;
            DivCB.Checked = false;
            SubCB.Checked = false;
            MulCB.Checked = false;
        }
    }

    private void SubCB_CheckedChanged(object sender, EventArgs e)
    {
        if (SubCB.Checked == true)
        {
            operation = 4;
            DivCB.Checked = false;
            AddCB.Checked = false;
            MulCB.Checked = false;
        }
    }

    private void oneDCB_CheckedChanged(object sender, EventArgs e)
    {
        if(oneDCB.Checked == true)
        {
            digits = 1;
            twoDCB.Checked = false;
            threeDCB.Checked = false;
        }
    }

    private void twoDCB_CheckedChanged(object sender, EventArgs e)
    {
        if ( twoDCB.Checked == true)
        {
            digits = 2;
            oneDCB.Checked = false;
            threeDCB.Checked = false;
        }
    }

    private void threeDCB_CheckedChanged(object sender, EventArgs e)
    {
        if (threeDCB.Checked == true)
        {
            digits = 3;
            oneDCB.Checked = false;
            twoDCB.Checked = false;
        }
    }
    private void button8_Click(object sender, EventArgs e)
    {
        // operations: 1. (*) 2. (/) 3. (+) 4. (-)
        // digits are as number indicates.



        // Second window popup.
        // it's the question form, right?
        Form2 questionForm = new Form2();
        //"Write" your settings in the other form's variables
        //You will have to write code that finds out which checkbox is which number! For now its fixed.
        questionForm.operation = 2;
        questionForm.digits = 1;
        questionForm.Show();
        //Hide Form1
        this.Hide();
    }
}
}

Form2:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FinalProject
{

public partial class Form2 : Form
{
    public static int operation;
    public static int digits;


    public Form2()
    {
        InitializeComponent();

    }

    //do NOT paste this. It can be added by creating an event handler
    // you also might not need this, but this method is called when this Form appears. It's an example.
    // https://msdn.microsoft.com/en-us/library/zwwsdtbk(v=vs.80).aspx
    private void Form2_Load(object sender, EventArgs e)
    {
       //here you can use your variables for example (also anywhere within this class!)
       //e.g.
       Textbox1.Text = (string)operation;   
    }

    private void FinishedBtn_Click(object sender, EventArgs e)
    {


    }
}
}
rudib
  • 227
  • 1
  • 10