2 Replies Latest reply on Sep 3, 2012 5:10 AM by kellydn

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

    kellydn
      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
        • Re: Assigning X,Y coordinates to a point using VB.net
          skutz
          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
          • Re: Assigning X,Y coordinates to a point using VB.net
            kellydn
            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.