Click here to Skip to main content
15,861,172 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a project that Im working on, im helping a couple of students with this and in the process teaching myself also.

The Scope of the project is to create a picture slideshow with a picturebox and visual C++.

There will be a next and previous and a slideshow start which will work with a timer control.

Im taking this step by step.

I started and figured out to declare an array.

Now I just for a test created an empty label wherein to display the names I put in the array.

I declared the array under:

public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here

array<string^>^ names = gcnew array<string^>(9) {
"Andre", "Crespo", "Iribarren",
"Jimenez", "Moran", "Palaveccino", "Simon",
"Torres", "Urdaneta"};

int i = 0;

I placed this code under the button:

while(i < 9)
{
label1->Text = names[i];

i++;
}

Theoretically once the button is pressed the label will show the first name in the array, then the second time its pressed the second name, etc. I need to get this working in order to continue my testing and get to the next step where ill add a timer and have it circulate the names when I press play.
Posted
Updated 15-Jul-13 7:09am
v2
Comments
[no name] 15-Jul-13 10:58am    
"Theoretically once the button "... no theoretically, your label text will be set to all of the strings in your names array one at a time, leaving the final string as the label text as "Urdaneta" after your while loop has finished.
Har Dus 15-Jul-13 11:05am    
Yes, thats what I meant. I will then add a extra if statement that when the array reaches the last name to reset the value back to 0, thus looping the whole story.
[no name] 15-Jul-13 11:32am    
So what is the question? If you just add an if statement to this that resets i back to 0 then you will have an infinite loop that will never allow your form to load. And if you put this code into a button click handler then you will have an infinite loop that will never allow your button click handler to exit.
Har Dus 15-Jul-13 12:13pm    
Thw question is that it dows not work, it does not see the array I put ontop feom inside the button. Tells me everything inside the button is undeclared. How can I get it to see thw array.
[no name] 15-Jul-13 12:19pm    
It's because you have declared your array in a local scope to your form load event.

1 solution

Har Dus wrote:
Theoretically once the button is pressed the label will show the first name in the array, then the second time its pressed the second name, etc.
Who told you so?

You did not even try to do anything like that. Instead, you just run some names until the 8-the one, changing the text of a label. The loop finishes leaving the UI with the last value of the name, and all previous ones are just lost. Besides, you don't even try to do anything with you picture boxes.

Sorry, but I don't even have a gut to explain what you could do instead. Nothing like what you tried. Perhaps, find some code sample of, say, a wizard, or a slide show, which is simple enough… I would rather advise you not to go in for UI until you get more comfortable with some simplest programming.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900