Sunday, August 2, 2009

How do I add something to an array in Visual Basic?

If I've already declared an array, what do I do to add more to it?

How do I add something to an array in Visual Basic?
You can use the incremental counter.


Make you you have a null reference after the array name. MyArray()





Dim MyArray() as String, Counter as Integer = 0





MyArray(Counter) = Counter


Counter += 1





OR





You can do this





MyArray(MyArray.Length() ) =MyArray.Length() .ToString





OR whatever you want
Reply:Dim a





a=Array(1,2,3)





b = a(0) ' b is now 1


b = a(1) ' b is now 2





ReDim Preserve a(4)





a(3) = 4





b=a(3) ' b is now 4

pollen

No comments:

Post a Comment