How would I alter the size of an array at run-time? I want to read the list of processes and stick each one into a slot in an array, but the number of processes can change alot.
Altering Size of Arrays
Collapse
X
-
Take a look at ReDimOriginally posted by TNTHow would I alter the size of an array at run-time? I want to read the list of processes and stick each one into a slot in an array, but the number of processes can change alot. -
If u r using redim then must have a lok on preserve kwd alsoOriginally posted by willakawillTake a look at ReDim
dim myArray() as string
myarray(0)="XYZ "
Redim Preserve myArray(10)Comment
-
This is not normally correct. The preserve version is only used if you want to increase the size of the array while retaining the original contents. It is not used if you simply want to dynamically size the array at run time.Originally posted by vijaydiwakarIf u r using redim then must have a lok on preserve kwd also
dim myArray() as string
myarray(0)="XYZ "
Redim Preserve myArray(10)Comment
-
I've just given the ideaOriginally posted by willakawillThis is not normally correct. The preserve version is only used if you want to increase the size of the array while retaining the original contents. It is not used if you simply want to dynamically size the array at run time.Comment
-
Not just the idea.Originally posted by vijaydiwakarI've just given the idea
This code will not work. You will get a 'subscript out of range' error
Code:dim myArray() as string myarray(0)="XYZ"
Comment
-
When you are going to dynamically size an array you would follow this pattern:Originally posted by TNTSo what code will work?
If you already have an array with data stored in it and you wish to resize it to accept more data:Code:Dim ar() As Integer Dim size As Integer size = 25 ReDim ar(size)
Code:size = 35 ReDim Preserve ar(size)
Comment
Comment