Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6244535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:20:35+00:00 2026-05-24T12:20:35+00:00

Ok I am confused by this, I have: a int variable a string array

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:20:36+00:00Added an answer on May 24, 2026 at 12:20 pm

    You’re missing image08.jpg, which means there are only 21 entries in your array, not 22. Therefore when ticker is 21, you’ll get an exception.

    One way of making this more robust is to use:

    if (ticker < pictureArray.Length - 1)
    {
        ticker++;
    }
    else
    {
        ticker = 0;
    }
    

    Or with a conditional:

    ticker = ticker < pictureArray.Length - 1 ? ticker : 0;
    

    Or with Richard’s “unconditional increment, conditional reset”.

    Or possibly the somewhat simpler:

    ticker = (ticker + 1) % pictureArray.Length;
    

    Admittedly in this case that would cause you to miss what I suspect is the real problem – you haven’t got all the images you’re expecting to have.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm confused with range of values of Int variable in C. I know that
This has always confused me. It seems like this would be nicer: ["Hello", "world"].join("-")
I am a little confused here. I would like to do something like this:
let's say I have std::map< std::string, std::string > m_someMap as a private member variable
I have been presented with this code which looks unnatural to me. I would
One thing that's always confused me is how a BackgroundWorker seems to have thread-safe
The first thing i would like to say is that this is not exactly
I have an object that has a KeyValuePair type property. I would like to
I have a .txt file looking like this: 1 Some string Some other string
It's likely that I'm just confused and wouldn't want to do this if I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.