2011-09-30

Assing an array as object property in Visual Basic 2010

I am not yet completely sure about how correctly this is, but it took a lot of time for me figuring out how to assign an array as a property.
I found out that firstly I had to define an array variable inside a class

Private temperatureArray() As Double

Then I have to make a property, which returns element of the array


    Public ReadOnly Property temperatureVal(ByVal index As Integer) As Double
        Get
            Return temperatureArray(index)
        End Get
    End Property


And finally I have to assign the values to an array inside a function or sub


    Sub getTemp()
        ReDim tempVal(UBound(valuesArray)) 'valuesArray is some predefined array.
        For i = 0 To UBound(valuesArray)
            temperatureVal(i) = valuesArray(i)
        Next i
    End Sub

Nav komentāru:

Komentāra publicēšana