I need a simple dynamic array for strings in a sub.
I want to add a string value to the array and later on the sub read the array. I know how to read from the array but how do you add.
Printable View
I need a simple dynamic array for strings in a sub.
I want to add a string value to the array and later on the sub read the array. I know how to read from the array but how do you add.
preserve will keep your previous value,if not useCode:Dim myarray() as string
redim preserve myarray(new_size) as string
myarray(new_size-1)= "string"
your previous value will be gone!!!
that would make the array contain a nullstring at myarray(new_size)
Well you could redimension without having a counter
Code:Redim preserve myarray(ubound(myarray)+1)
myarray(ubound(myarray))="String"
Works like a charm.