Reputation: 47
I have some probably simple to solve issue with accessing array of floats inside an array of class objects. Inside my Excel document I declare a class TData with some properties like
Public weight As Double
Public segments As Variant
Then inside a module I declare an array of objects and a function to modify the data:
Dim dataset(126) As Object
Function modify()
Set dataset(0) = New TData
dataset(0).weight = 50
dataset(0).segments = Array(5.5,2,1)
Debug.Print dataset(0).segments(0) ' this produces an error 451
t = dataset(0).segments
Debug.Print t(0) ' this is fine and prints the correct answer
End Function
If I try to access the value directly with line "dataset(0).segments(0)" I'll get an error 451 "Property let procedure not defined and property get procedure did not return an object". If I assign the array to a variable first, I can access the value.
Now I don't understand why I can't access the value of the nested array. I guess it's some specific syntax which I didn't find anywhere. The thing is, when I add "dataset(0).segments" to the watches, it lists the values with exactly the above notation of "dataset(0).segments(0..2)".
Upvotes: 1
Views: 478
Reputation: 129
Credit to Tim:
I've deleted my previous Answer and replaced it with what Tim provided and was accepted by auther. The error was a syntax error even I failed to catch. I'm changing my answer for the community, but 100% credit goes to Tim. If Tim posts the answer he should get the accepted answer check mark.
Debug.Print dataset(0).segments()(0)
Upvotes: 1