tags:

views:

195

answers:

3

I have a piece of code written in Visual Basic:

Dim n As Double, i As Integer
n = 4
Dim Ramp_length(1 To 4) As Double
For i = 1 To n
    Ramp_length(i) = Cells(13 + i, 5)
    'Cells(65 + i, 7) = Ramp_length(i)'
Next i

Is there a way I can reproduce the result without declaring the array with a "fixed" length? I eventually want the code to read off a column of data with unknown length and store it in an array of equal or smaller length so it can be altered. This is just a piece of the code...if someone could help me out that would be great! :D

Thanks

A: 

There's no such a thing, array with "dynamic" length.

You can, however, encapsulate some logic that will resize the array whenever needed (this is known as ResizeArray in some languages, List in others, or ArrayList; I'm sorry, I don't know exactly which one in VB; if it's VB.NET then use "List").

Bruno Reis
A: 

You could use an ArrayList. It's the closest you can come to a dynamic array. There are other collections as well, so it may come down to what you expect to do with the data. However, you can't create an array and vary it's length dynamically in vb. (Well, not efficiently :) )

keyboardP
+1  A: 

Not sure if this is what you're looking for:

    Dim n As Double = 44
    Dim Ramp_Length_List As New List(Of Double)
    For i As Integer = 1 To n
        Ramp_Length_List.Add(Your_Temp_Double)
    Next i

    Dim Ramp_Length(Ramp_Length_List.Count - 1) As Double
    For i As Integer = 0 To Ramp_Length_List.Count - 1
        Ramp_Length(i) = Ramp_Length_List(i)
    Next
    Ramp_Length_List = Nothing
    'Ramp_Length() as Double is now sort of dynamic.
CowKingDeluxe