Arrays of Unknown Length in Visual Basic

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 to reproduce the result without declaring a fixed-length array? Ultimately, I want the code to read a column with an unknown length and store it in an array of equal or shorter length so that it can be changed. This is just part of the code ... if someone can help me, it will be great !: D

thank

+3
source share
4 answers

Not sure if this is what you are 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.
+1
source
Dim DynaStrings() As String
ReDim DynaStrings(10)
DynaStrings(0) = "String 0"
'Need more data space!
ReDim DynaStrings(100)
DynaStrings(50) = "String 50"

Hope this helps.

+1
source

, "" .

, ( ResizeArray , List in others ArrayList, , , VB, VB.NET, "" ).

0

You can use an ArrayList . This is closest to a dynamic array. Other collections exist, so this may lead to what you expect to do with the data. However, you cannot create an array and dynamically change its length in vb. (Well, not effective :))

0
source

Source: https://habr.com/ru/post/1728532/


All Articles