There are alot of things going on with your code that can't be determined from your post, some things jump right out that will cause problems and still other things that you could do to resolve the issue you are having. There is also alot of extra code that isn't necessary .. at least it appears unecessary based on the snippet you provided.
Lets start with something simple.
You want to create a continuous string of comma delimited values to use for another purpose.
Question: Do you need X,Y and Z coordinates or just X and Y?
Ok, now, I have noticed that you Dim the variable just prior to setting its value. Unless there is more to your code, when you Dim a variable, if there was a previous incarnation of that variable, its value will be lost. To prevent this, you should Dim the variable outside the loop where you are setting the values to the string.
Great ... now you should have something like this:
Dim result As String
While (gettingValues = True)
Dim pointidnumber(0) As Object
pointidnumber(0) = myPoint.PointNumber
result &= CStr(pointidnumber(0)) & ","
Wend
Notice in the above code that the string
result is Dimmed outside the loop where it is being set. This ensures you do not redim the variable and lose its previous value.
This is a good way to handle creating your strings. However, because you need to use this string elsewhere in your code, it makes sense to create a private variable in the class that can hold your string value. This is because your variable result will go out of scope when the function ends.
Lets do this by adding a private variable in the class.
Class myClass
Private _results As String = ""
'Other code here
Public Sub getPointsFromObject(ByRef myPoint As Object)
_results &= CStr(myPoint.PointNumber) & ","
End Sub
End Class
Now, you can see in the above code, the point is passed as a reference to the sub, which extracts the points values and appends them to the string (along with a comma)
This may be good enough, but lets make it alot better, perhaps you want to have more control over the point list .. the problem with the point list as it is now, is that you have to remove the final comma when you pass it to your other function. So, lets make a comma delimited string class that you can pass your values into.
Public Class CDFPointsString
'Initialize private variables
Private _strCDFString As String = "" 'String is empty in new class
Private _is3d As Boolean = False 'Class initializes as 2d point string
'Method to return the number of points in the string
Public Function PointCount() As Long
Dim count As Long = 0
'Note: Arrays are zero based so there are UBound + 1 elements in the array
If _is3d Then
'Set count to the number of 3d points in the string
count = (UBound(Split(_strCDFString, ",")) + 1) / 3
Else
'Set count to the number of 2d points in the string
count = (UBound(Split(_strCDFString, ",")) + 1) / 2
End If
Return count
End Function
'Method to get string of points
Public Overrides Function ToString() As String
'Remove the last comma and return the remainder of the string
Return _strCDFString = _strCDFString.Remove(_strCDFString.LastIndexOf(","), 1)
End Function
'Property to get the point type
Public ReadOnly Property Type() As PointType
Get
Return If(_is3d = True, PointType.Point3D, PointType.Point2D)
End Get
End Property
'Property to determine if the string is empty
Public ReadOnly Property IsEmpty() As Boolean
Get
Return _is3d = ""
End Get
End Property
'Method to add a comma delimited list representing a point to string
Public Function AddPoint(ByVal PointList As String) As Boolean
Dim tempArray As Object
Dim tempString As String = ""
Dim count As Integer = 0
Dim rVal As Boolean = False
'Count the points in the list
tempArray = Split(PointList, ",")
For X As Integer = 0 To UBound(tempArray)
If tempArray(X) <> "" Then
count += 1
'Add the point to the temp string - This effectively removes any errant
'empty values such as "1,,3" and turns it into "1,3,"
tempString &= tempArray(X) & ","
End If
Next X
'If our point is the same type as being stored in this class, add it to the point list
'Note that a 2d point list cannot be added to a 3d list and a 3d point list cannot be added to a 2d list
If ((_is3d = True And count = 3) Or (_is3d = False And count = 2)) Then
_strCDFString &= tempString
rVal = True 'The function succeeded
Else
rVal = False 'The function failed - mismatched point type
End If
Return rVal
End Function
'Constructors - Default constructor creates a 2d point list
Public Sub New()
_is3d = False
End Sub
'Pass True to create a 3d point list
Public Sub New(ByVal is3d As Boolean)
_is3d = is3d
End Sub
'Enum for point type in this string
Enum PointType
Point2D = 0 'This is a 2d string list
Point3D 'This is a 3d string list
End Enum
End Class
To use this example class, follow this example:
Private _points As CDFPointsString = New CDFPointsString(False) 'This is a 2d point list change to True for a 3d point list
Public Sub AddToString(ByRef MyPoint As Object)
_points.AddPoint(CStr(MyPoint.PointNumber))
MsgBox("Count: " & vbTab & _points.PointCount.ToString() & vbCrLf & _
"Type: " & vbTab & [Enum].GetName(GetType(CDFPointsString.PointType), _points.Type()) & vbCrLf & _
"IsEmpty: " & vbTab & _points.IsEmpty.ToString() & vbCrLf & _
"Value:" & vbCrLf & _points.ToString()
)
End Sub
If you need any more help feel free to ask