Array size trouble

WeslyWest
08-26-2002, 02:11 PM
How do i create an array that has a different number of values everytime it is used. I have a variable called TotalNumber that defines the length of the array but cannot put it in the dim statement, any help, thanks.

Thinker
08-26-2002, 02:18 PM
Start by declaring a dynamic array with...
Dim myarray() As Long 'or whatever type you need

Then when you are ready to size it, use...
ReDim myarray(TotalNumber) 'might want to use TotalNumber - 1

Ronq
08-26-2002, 02:18 PM
To do that you have to use redim, if you want to get it bigger or smaller but don't loose the data in the array you have to use redim preserve. For example like this:


Dim Array() as Long
Dim TotalNumber as Long

TotalNumber = 10

Redim Array(Totalnumber)

Redim Preserve Array(Totalnumber +3)



You may also want to look in the help for:
Ubound
Lbound

Bye.
Ronq.

Mikecrosoft
08-26-2002, 02:19 PM
use ReDim

You need to Dim there:

Dim YourArray() as Long

Then whe you need change the array size do this:

ReDim YourArray(NewSize)

if you don't need erase the content of the array use Preserve:

Redim Preserve YourArray(NewSize)

Preserve only use to change the first dim of the array, this mean, you can't Redim Preserve this:

Redim Preserve (12,NewValue) as long

but you can Redim Preserve this:

Redim Preserve (NewSize,12) as Long

:)

I hope help !!

NateBrei
08-26-2002, 02:37 PM
Preserve only use to change the first dim of the array, this mean, you can't Redim Preserve this:

Redim Preserve (12,NewValue) as long

but you can Redim Preserve this:

Redim Preserve (NewSize,12) as Long
I thought it was the other way around. I thought you could only ReDim the LAST dimension.

Nate

Thinker
08-26-2002, 03:07 PM
You are correct Nate. Only the last one.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum