开发者

an efficient way acess a range in a user defined type?

I've got a user defined type with about 5000 entries. I would like to select a range of the data in about 1,000 entry blocks and use it as an array. Is there a way to do this without looping?

Something like

 MyArray = MyType(1:1000).property

rather than

 for i = 1 to 1000
     MyArray(i) = MyType(i).property
 Next i

Thanks开发者_如何学Go!


No, there is no way to convert a collection of elements into an array without looping or special accessor methods for the type - let alone convert a common property from a collection of elements into an array.

The only objects that support anything like this are Range objects, for which you can convert certain properties of an array of cells (range) into an array using:

MyArray = Range("A1:A1000").Value

Again, nothing like this is available for other types unless the programmer goes through the trouble of defining the behaviour - and even if they did define it, odds are the method would likely include iterating over the elements anyways, just within the type class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜