Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27358

VS 2005 Accessing class variable values of an array of type customclass.

$
0
0
I am attempting to efficiently (w/o looping) access all of the class variable values of a large-ish array of type customclass. The snippet below details what I want to do. Any suggestions are greatly appreciated. Thanks.

Public Class Coords
Public X As Double
Public Y As Double
Public Z As Double
End Class

Module Module2
Sub TestIt()
'Create and populate array of custom class
Dim CoordArray(1000) As Coords
Dim ubA As Short = UBound(CoordArray)
For p As Short = 0 To ubA
CoordArray(p).X = p
CoordArray(p).Y = 2 * p
CoordArray(p).Z = p ^ 2
Next p

'Attempt to create array containing all of
'the Y values without looping thru array
'None of these syntax attempts work
Dim YVals(ubA) As Double
YVals = CoordArray.Y
YVals = CoordArray{}.Y
YVals = CoordArray().Y
YVals = {CoordArray.Y}

'Any ideas or suggestions for how to
'efficiently do this (ie no looping)
'Any other tricks??
End Sub

End Module

Viewing all articles
Browse latest Browse all 27358

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>