Array starting at One
I'm trying to make a array start at 1 and go to 600, i tryed using "to" but never worked.
ReDim
Preserve Array(1 to 600)I'm trying to make a array start at 1 and go to 600, i tryed using "to" but never worked.
ReDim
Preserve Array(1 to 600)ReDim re-dimensions your array - Take a look at this:
http://msdn2.microsoft.com/en-us/library/c850dt17.aspx
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vastmReDim.asp
the "to" syntax is not valid in this situation. The ReDim will make your array larger (or if smaller then the elements in the "large"/"high" area are lost)
I think the documentation explains it better and hope it helps :-)
just to add, since I can't edit my original post, if you are trying to make an array of a fixed size, then you do this:
Dim theArray(size) as type
so if I had a string array and wanted its size to be 10:
Dim theStringArray(10) as String
ok I think I understand - so basically you want to INCREASE the size of the array correct? if so, then yes the Redim is what you are after and you need to specify the size to increase up to as stated in the doc
so if we had an array size of 4:
Dim theArray(4) as string
and we wish to increase it later to 6 then:
ReDim preserve theArray(6)
then to resize it again to say, 8, you do the same thing:
ReDim preserve theArray(8)
does this help?
Even though VB 2005 now allows the "to" syntax in redim preserve statements, you must declare the array with a lower bound of 0 (as in 2003 and 2002).
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter, VB to C++ converter
Clear VB: Cleans up VB code
C# Code Metrics: Quick metrics for C#
You still dont understand, what i'm trying to do is start with 1 and then go up to 600, so its 1, 2, 3, 4, ....., not 0, 1, 2, 3, ......
For example in vb6 i could have used, but i'm using vb.net
ReDim Array(1 To 600) As Byte
So that it starts at 1 and goes up NOT 0 and up
what David said is correct, it always starts from 0. Why must you have it at 1? :-)
In the IDE if you do this:
Dim test() as string
Redim preserve test(1 to 300)
the IDE will tell you, there will be a blue squiggle under "1" stating that "Array lower bounds can only be 0"