Ok I am confused by this, I have: a int variable a string array and a statement that all should would. Its pretty standard looping array structure.
public class Form1 : System.Windows.Forms.Form
{
public int ticker = 0;
public string[] pictureArray = new String[] {
"image01.jpg",
"image02.jpg",
"image03.jpg",
"image04.jpg",
"image05.jpg",
"image06.jpg",
"image07.jpg",
"image09.jpg",
"image10.jpg",
"image11.jpg",
"image12.jpg",
"image13.jpg",
"image14.jpg",
"image15.jpg",
"image16.jpg",
"image17.jpg",
"image18.jpg",
"image19.jpg",
"image20.jpg",
"image21.jpg",
"image22.jpg"
};
...
if (this.ticker < 21)
{
this.ticker++;
}
else
{
this.ticker = 0;
}
MessageBox.Show(pictureArray[ticker]);
It runs fine until ticker is > 21 then it crashes and states IndexOutOfRange but if I were to say change the MessageBox to just print ticker it is fine and I have no error. Now I have looked through similar questions but the problem is that I am a PHP programmer and I am not sure on some of them if the answers pertain to my situation.
Any help will be greatly appreciated, I think that I have all of the relevant information here if not I apologize. But everything works until it starts to recycle the array and run through the array again. I am just baffled.
this.tickercome from? Also, sure you don't wantif (this.ticker < pictureArray.Length)this.ticker), then you get an IndexOutOfRange Exception. Change it to <= 21.tickerwhen the exception is thrown? Is it thrown frompictureArray[ticker]line? This code look fine to me.tickeris a field in the form. Look at the top of the class.