My program does not work something is a little off

357mag

Well-known member
Joined
Mar 31, 2023
Messages
58
Programming Experience
3-5
I'm completely new to Windows programming but I figured I would try to write some simple, beginning type program today. So I got this program that has an integer array with 3 elements in it, and I'm using a loop to populate the array with the numbers 0, 1, and 2.

Then I use another loop to show the numbers in a TextBox when I click the button. Problem is the only number that shows in the TextBox is 2.

I figure since 2 (the last valid value of the loop control variable) , that is the only value I see in the TextBox.

But the quotation marks meaning put a space after an integer is added should take care of that, but it isn't.

Here is what I got:

private void button1_Click(object sender, EventArgs e)
{
int[] numbers = new int[3];
int t;

for (t = 0; t < 3; t++)
numbers[t] = t;

for (t = 0; t < 3; t++)
textBox1.Text = numbers[t] + " ";
}
 
in your second loop you are setting the text property of the textbox to numbers[t] + " " each time you are not appending to the existing text
 
So how do I fix it? I'm trying different things but no go so far. The quotation marks should take care of it. Works with console programming.
 
Last edited:
Yes I figured it out finally so I wrote this:

for (t = 0; t < 3; t++)
textBox1.Text = textBox1.Text + numbers[t] + " ";
 
Back
Top Bottom