Assigning X,Y coordinates to a point using VB.net

12322
2
09-02-2012 09:35 AM
DavidKelly1
New Contributor
I am converting vba code to run in VB.net in ArcGIS 10.  The code is supposed to read a text file of coordinates, creates points with the  X,Y coordinates.  When the code tries to set the value of x to pPoint(i).X, the code crashes. x and y both have the correct double values(coordinates).

Any body have an idea what I am doing wrong?



        Dim pointColl As IPointCollection4 = New Polygon

        Dim pPoint() As IPoint

        Dim i As Long = 10000

        ReDim pPoint(0 To CInt(i - 1))

        i = 0

        noCats = 1

        'Read coords into points

          Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(VSTabTextFile)
          MyReader.TextFieldType = FileIO.FieldType.Delimited
          MyReader.SetDelimiters(",")

          Dim currentRow As String()

          currentRow = MyReader.ReadFields()
          currentRow = MyReader.ReadFields()
          testPM = Convert.ToDouble(currentRow(0))
          PM = Convert.ToDouble(currentRow(0))

          While Not MyReader.EndOfData
                If testPM = PM Then
                    PM = Convert.ToDouble(currentRow(0))
                    x = Convert.ToDouble(currentRow(1))
                    y = Convert.ToDouble(currentRow(2))

                    pPoint(i).X = x
                    pPoint(i).Y = y

                    pointColl.AddPoint(pPoint)

                    i = i + 1

                    currentRow = MyReader.ReadFields()a polygon.
          end while
0 Kudos
2 Replies
ScottKutz
New Contributor II
David,

  I don't write in VB.Net, so I cannot provide exact syntax, but it does not appear that the point objects are ever "new"'ed in the sample code included in your post.

  In other words, before attempting to assign the X and Y coordinate values, it will be necessary to create an instance of the point object that is to be referenced through its IPoint interface.

  I'm confident there are samples in the ArcObjects developer help that will show VB.Net coding examples on how to "new" a new instance of a point object.

  I hope this information is of use.

Scott
0 Kudos
DavidKelly1
New Contributor
David,

  I don't write in VB.Net, so I cannot provide exact syntax, but it does not appear that the point objects are ever "new"'ed in the sample code included in your post.

  In other words, before attempting to assign the X and Y coordinate values, it will be necessary to create an instance of the point object that is to be referenced through its IPoint interface.

  I'm confident there are samples in the ArcObjects developer help that will show VB.Net coding examples on how to "new" a new instance of a point object.

  I hope this information is of use.

Scott


Thank you Scott you were right, by creating a new point I was able to get it to work.
0 Kudos