Dynamic Arrays

gazeranco

Well-known member
Joined
Feb 11, 2006
Messages
45
Location
Englandshire!
Programming Experience
Beginner
Hello could someone provide me with a code example for the following...

I want to create a dynamic array of type string and i want to tell it how big it will be using a variable(int) at runtime and then i want to add a list of strings to it by using a variable which will contain strings at runtime, it will assign the values using a for next loop each time the loop executes the string will be different and i want that string to be added to my array so on so forth, any ideas? :confused:
 
Does this not work:

VB.NET:
Dim myArray(1) as String

ReDim myArrya(myInt)

-tg
 
well yeah but thats not the bit im stuck on, i can say

VB.NET:
Dim myarray() as string
 
redim myarray(myint)

The bit I can't do is add the strings that i want into it, the strings are from an xml file i want to store them in myarray to make it easy to move between the items... Im just not sure how i put the string items into the array :confused:

Or is this a rubbish way?

Thanks!
 
Homework anyone? If I'm reading this correctly then there is no need to ReDim, unless you're using the same array over and over. It looks to me like you simply declare a String array variable and specify the upper bound (which is one less than the length). You then just use a For loop to iterate from zero to the upper bound and set the element at that index.
 
Back
Top