New topic: Array Out of Bounds Exception - Windows IDE
<http://forums.realsoftware.com/viewtopic.php?t=46278> Page 1 of 1 [ 2 posts ] Previous topic | Next topic Author Message eugenedakin Post subject: Array Out of Bounds Exception - Windows IDEPosted: Tue Dec 18, 2012 12:49 pm Joined: Mon Jan 02, 2006 11:43 am Posts: 143 Location: Calgary, Alberta, Canada Hello Everyone, I am using the Windows IDE with Real Studio 2012 r2 on a Windows 8 machine and am getting the following error when attempting to put an integer value in an integer array. Quote:An exception of class OutOfBoundsException was not handled. The application must shut down. There are two lines of code in the program and I checked them with the online documentation at http://docs.realsoftware.com/index.php/Array. Here is the code that is placed in a pushbutton. Dim Array_Numbers() as Integer Array_Numbers(1) = 15 Here is the link to download an example program: RSArray.rbp. I must be missing something simple. Does anyone have some helpful suggestions? Thank you, Eugene Real Studio 2012 r2 Windows IDE Windows 8 Top charonn0 Post subject: Re: Array Out of Bounds Exception - Windows IDEPosted: Tue Dec 18, 2012 1:52 pm Joined: Mon Apr 02, 2007 2:08 am Posts: 1047 Location: San Francisco, CA, USA When you create an array, you can specify how large it is to be. If you don't, the array will be empty: Dim emtpyArray() As Integer 'Creates an array with nothing in it. Dim notEmptyArray(0) As Integer 'Creates an array with one element in it. If you attempt to read or write to an element which is outside the size of the array, you get an OutOfBoundsException. Your code creates an empty array and then tries to read the second (arrays are zero-based) element, which doesn't exist. To add an element to the end of an existing array without resizing it, use the Append method. To remove the last element in an array, use the Pop method. To resize an array, use Redim. Dim Array_Numbers(1) as Integer 'an array with two elements Array_Numbers(1) = 15 _________________ Boredom Software Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 2 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
