
I'm making a project in Winforms that's supposed to take values from the t Array, add them with the value inside a C variable that I have yet to declare and show the results in the tf textbox array when I press the FIFO button. My problem is that I can't seem to do this properly. I've been trying regular additions and whatnot to make sure that the contents of ti or t show on tf, and yet nothing seems to work at all. My main issue is that the program only takes the first value of the array, instead of taking them all. I'll be posting my code below.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
foreach (Control c in this.Controls)
{
if (c.GetType() == typeof(TextBox))
{
((TextBox)(c)).Text = "0";
}
}
}
private void fifo_Click(object sender, EventArgs e)
{
int c = 0;
int[] ti = { 0, 1, 2, 3, 4, 5 };
ti[0] = Convert.ToInt32(tiA.Text);
ti[1] = Convert.ToInt32(tiB.Text);
ti[2] = Convert.ToInt32(tiC.Text);
ti[3] = Convert.ToInt32(tiD.Text);
ti[4] = Convert.ToInt32(tiE.Text);
ti[5] = Convert.ToInt32(tiF.Text);
int[] t = { 0, 1, 2, 3, 4, 5 };
t[0] = Convert.ToInt32(ta.Text);
t[1] = Convert.ToInt32(tb.Text);
t[2] = Convert.ToInt32(tc.Text);
t[3] = Convert.ToInt32(td.Text);
t[4] = Convert.ToInt32(te.Text);
t[5] = Convert.ToInt32(tf.Text);
int[] tf1 = { 0, 1, 2, 3, 4, 5 };
tf1[0] = Convert.ToInt32(tfA.Text);
tf1[1] = Convert.ToInt32(tfB.Text);
tf1[2] = Convert.ToInt32(tfC.Text);
tf1[3] = Convert.ToInt32(tfD.Text);
tf1[4] = Convert.ToInt32(tfE.Text);
tf1[5] = Convert.ToInt32(tfF.Text);
for (int i = 0; i <= 0; i++)
{
ti[i] = tf1[i] + 5;
}
}
}
for (int i = 0; i <= 0; i++)i<=0which is what you are initializing it asint i = 0;. As a side note, instead of usingConvert.ToInt32(), you should look intoint.TryParse()to ensure that you will always have a valid value. The way you have it right now could throw an exception if the user inputs anything other than a numeric value.