Results 1 to 5 of 5

Thread: Index out of bound error when I know its not

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    48

    Index out of bound error when I know its not

    I am trying to run this loop

    Code:
                
                int y = 0;
                char[] tempmess = new char[] { };
                for (int a = 56; a < SMS.Length; a++ )
                {
                    tempmess[y] = SMS[a];
                    y++;
                }
    and I keep getting an index out of bounds exception when I know its not. SMS which is a char array has a length of 76. if I manually put in the number it works but if I try and loop it crashes long before it hits the end.

    EDIT: its an IndexOutOfRange Exception

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Index out of bound error when I know its not

    Which line is highlighted wit the error?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Index out of bound error when I know its not

    What is the value of a and y when this happens?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Index out of bound error when I know its not

    Hmm, perhaps if tempmess[] was defined to have more than 0 elements...
    W o t . S i g

  5. #5
    New Member
    Join Date
    Jan 2011
    Posts
    1

    Re: Index out of bound error when I know its not

    Couldn't you use something like this?
    Code:
               char[] subSMS = SMS.ToString().Substring(56).ToCharArray();
    I know that's probably really bad coding and perhaps inefficient but I'm kind of new with this sort of thing.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width