atmosphere1212 Posted October 12, 2004 Posted October 12, 2004 Im just wondering if its possible to change the dimension of an array thats already created to 0. I tried redim preserve(0) but the length becomes 1. Also does anyone know how to convert an ArrayList to a 1-dimensional array of some type. Quote
*Experts* mutant Posted October 12, 2004 *Experts* Posted October 12, 2004 Why would you want to preserve anything in the array that is getting completely emptied? But that aside, you can redim it to -1 if you want to set its capacity to 0. To convert an Arraylist to an array use its ToArray method. Quote
mskeel Posted October 14, 2004 Posted October 14, 2004 Yeah, I just figured this out the other day. VB uses a standard 0 indexed array but when you declare an array you aren't actaully declaring the size but the last index. A collegue's theory is that it's an old throw back from VB6 when arrays where indexed starting at 1. The end result was an array the size you declared it and ending at the index you declared. To illistrate... Dim list(3) as string ==> list.length = 4 (list(0), list(1), list(2), list(3)) So redim preserve(0) is saying that you want an array with ending index 0 (length = 1) Quote
golfnut1969 Posted October 14, 2004 Posted October 14, 2004 ...old throw back from VB6 when arrays where indexed starting at 1... VB6 arrays where indexed starting at 0, unless you specified otherwise (eg. list(1 to 3)) Quote
mskeel Posted October 14, 2004 Posted October 14, 2004 VB6 arrays where indexed starting at 0' date=' unless you specified otherwise (eg. list(1 to 3))[/quote'] Thanks for the clarification. So I guess this phenomenon is just a part of VB. As I said, that was the theory. My original comment still stands...unless someone has a greater insight on why VB doesn't do arrays the way everyone else does. Quote
Leaders Iceplug Posted October 15, 2004 Leaders Posted October 15, 2004 Because of legacy Basic versions. The number representing the array is always the upperbound. While that was fine back then since you could actually do Dim Myarray(0 To 9) As Integer 'Clearly this is 10 items. In .NET, you cannot define both indices (even if it is just to make yourself know that the bottom bound is always 0). So, now you can only specify one number (which is the upperbound and not the count). Dim MyArray(9) As Integer 'Looks like 9 elements but is 10. This is something that needs addressing in some version of VB.NET. At the very least the '0 To' should be back there. Just a minor annoyance. I've had to get used to it. :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.