Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Let and Get array of fixed size

Tags:

arrays

excel

vba

I have a class that has a fixed-size array of Double, for example

Private m_values(8) as Double

What is the correct syntax for the Let and Get methods for an array?

Public Property Let Values (RHS(8) as Double)
    m_values = RHS
End Property

Public Property Get Values() as Double
    Values = m_values
End Property

The specific parts of the syntax I am unclear about:

a. In the Let method, is RHS(8) as Double the correct way to pass an array of 8 Double?
b. Can I copy one array to another simply using assignment? (e.g. m_values = values)
c. For the Get method, is it correct for the function to be declared as Double or should it be something like as Double(8)?

like image 443
Cory Kramer Avatar asked Aug 17 '15 17:08

Cory Kramer


People also ask

How do you fix the size of an array?

The simple answer is that you cannot do this. Once an array has been created, its size cannot be changed. Instead, an array can only be "resized" by creating a new array with the appropriate size and copying the elements from the existing array to the new one.

How do you create an array of fixed lengths?

Use a tuple to declare an array with fixed length in TypeScript, e.g. const arr: [string, number] = ['a', 1] . Tuple types allow us to express an array with a fixed number of elements whose types are known, but can be different. Copied! We declared a tuple with 3 elements with types of string , number and number .

Is array fixed size in Swift?

Swift doesn't have fixed size arrays, and I guess many of us have experimented with various workarounds. I thought it would be fun to share and discuss our ways around Swift's lack of fixed size arrays here.

Do JavaScript arrays have fixed size?

A. length will always be 2. This is the way that typed arrays (eg Float32Array ) already work. They have fixed size.


1 Answers

The only way to declare a property that can hold arrays is as Variant property.

Private m_values As Variant

Public Property Let Values(RHS As Variant)
    m_values = RHS
End Property

Public Property Get Values() As Variant
    Values = m_values
End Property

Public Sub Test()
    Dim x(8) As Double
    x(1) = 123.55
    x(2) = 456.45
    x(5) = 789.66
    x(8) = 123.777

    ' assign value to property
    Values = x

    ' get value from property
    Dim y() As Double
    y = Values

    Dim i As Integer
    For i = 0 To UBound(y)
        Debug.Print y(i)
    Next

End Sub
like image 70
Pradeep Kumar Avatar answered Sep 19 '22 20:09

Pradeep Kumar