C
C#ā€¢13mo ago
FloW

every generated textBox has a diferent value but all arrey values is 0 .

Why?
13 Replies
SinFluxx
SinFluxxā€¢13mo ago
$details
MODiX
MODiXā€¢13mo ago
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, and what you expect the result to be. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
FloW
FloWOPā€¢13mo ago
No description
No description
FloW
FloWOPā€¢13mo ago
I know , just forget to make screenshots šŸ˜…
SinFluxx
SinFluxxā€¢13mo ago
I mean, they're not really that helpful either
FloW
FloWOPā€¢13mo ago
can I paste code ?
SinFluxx
SinFluxxā€¢13mo ago
$code
MODiX
MODiXā€¢13mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
FloW
FloWOPā€¢13mo ago
thank you!
int[] arr = new int[300];
private void button1_Click(object sender, EventArgs e)
{
Random randomGenerator = new Random();
for (int i = 0; i<15; i++)
{
for (int j = 0; j<20; j++)
{
int TextNum = randomGenerator.Next((int)numericUpDown1.Value, (int)numericUpDown2.Value);
arr.Append(TextNum);
TextBox textBox = new TextBox()
{
Text = TextNum.ToString(),
Location = new Point(40 + 105 * i, 40 + 30 * j),
Width = 100,
Height = 25,
};

Controls.Add(textBox);
}
}

for (int i=0; i<arr.Length; i++)
{
Console.WriteLine(arr[i]);
}
}
int[] arr = new int[300];
private void button1_Click(object sender, EventArgs e)
{
Random randomGenerator = new Random();
for (int i = 0; i<15; i++)
{
for (int j = 0; j<20; j++)
{
int TextNum = randomGenerator.Next((int)numericUpDown1.Value, (int)numericUpDown2.Value);
arr.Append(TextNum);
TextBox textBox = new TextBox()
{
Text = TextNum.ToString(),
Location = new Point(40 + 105 * i, 40 + 30 * j),
Width = 100,
Height = 25,
};

Controls.Add(textBox);
}
}

for (int i=0; i<arr.Length; i++)
{
Console.WriteLine(arr[i]);
}
}
šŸ˜Š
SinFluxx
SinFluxxā€¢13mo ago
arr.Append(TextNum); Append will create a new sequence, it won't add anything into your existing arr variable Even if you updated arr to be the new sequence that Append gives you, because you've declared arr with a size of 300, you'll end up with an array of 300 0s and then the new TextNum value on the end
FloW
FloWOPā€¢13mo ago
so arr[301] will be TextNum right?
SinFluxx
SinFluxxā€¢13mo ago
that's right - if you make sure to assign the newly created sequence to your arr variable What would probably make more sense is trying to set the value at the index of the array you're currently at? arr[0] = TextNum, arr[1] = TextNum, etc?
FloW
FloWOPā€¢13mo ago
hm i tried to do it using for I`ll try again , thank you one more question I need to change int[300] to int[0] or no?
for (int i = 0; i<15; i++)
{
for (int j = 0; j<20; j++)
{
int TextNum = randomGenerator.Next((int)numericUpDown1.Value, (int)numericUpDown2.Value);
arr[i * j] = TextNum;
TextBox textBox = new TextBox()
{
Text = TextNum.ToString(),
Location = new Point(40 + 105 * i, 40 + 30 * j),
Width = 100,
Height = 25,
};

Controls.Add(textBox);
}
}
for (int i = 0; i<15; i++)
{
for (int j = 0; j<20; j++)
{
int TextNum = randomGenerator.Next((int)numericUpDown1.Value, (int)numericUpDown2.Value);
arr[i * j] = TextNum;
TextBox textBox = new TextBox()
{
Text = TextNum.ToString(),
Location = new Point(40 + 105 * i, 40 + 30 * j),
Width = 100,
Height = 25,
};

Controls.Add(textBox);
}
}
what do you think? update:
int[,] arr = new int[15, 20];
private void button1_Click(object sender, EventArgs e)
{
Random randomGenerator = new Random();
for (int i = 0; i<15; i++)
{
for (int j = 0; j<20; j++)
{
int TextNum = randomGenerator.Next((int)numericUpDown1.Value, (int)numericUpDown2.Value);
arr[i, j] = TextNum;
TextBox textBox = new TextBox()
{
Text = TextNum.ToString(),
Location = new Point(40 + 105 * i, 40 + 30 * j),
Width = 100,
Height = 25,
};

Controls.Add(textBox);
}
}

for (int i=0; i<15; i++)
{
for (int j = 0; j < 20; j++)
{
Console.WriteLine(arr[i, j]);
}
}
}
int[,] arr = new int[15, 20];
private void button1_Click(object sender, EventArgs e)
{
Random randomGenerator = new Random();
for (int i = 0; i<15; i++)
{
for (int j = 0; j<20; j++)
{
int TextNum = randomGenerator.Next((int)numericUpDown1.Value, (int)numericUpDown2.Value);
arr[i, j] = TextNum;
TextBox textBox = new TextBox()
{
Text = TextNum.ToString(),
Location = new Point(40 + 105 * i, 40 + 30 * j),
Width = 100,
Height = 25,
};

Controls.Add(textBox);
}
}

for (int i=0; i<15; i++)
{
for (int j = 0; j < 20; j++)
{
Console.WriteLine(arr[i, j]);
}
}
}
its working Thank you very much!
Want results from more Discord servers?
Add your server