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.

ReDimPreserve Array(1 to 600)

[256 byte] By [DarkDarkDark] at [2007-12-24]
# 1
sorry for double post, said it had a error and i didn't think it would post so i remade it to try again
DarkDarkDark at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2

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 :-)

ahmedilyas at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3

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

ahmedilyas at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 4
I looked at it and i dont think that can help me, i want the array to start off at 1 and go up instead of 0
DarkDarkDark at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 5

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?

ahmedilyas at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 6

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#

DavidAnton at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 7

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

DarkDarkDark at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 8
Ahhhh okay
DarkDarkDark at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 9

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"

ahmedilyas at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 10
Well, i did in fact do that but it never showed me that and with what i'm trying to do i thought i needed to start at 1 but i dont. Thanks for all the help
DarkDarkDark at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 11
no worries, glad we could all help - that's what its about!
ahmedilyas at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...