+ Reply to Thread
Results 1 to 3 of 3

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

  1. #1
    David Kelly
    Join Date
    May 2010
    Posts
    34
    Points
    1
    Answers Provided
    0


    0

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

    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

  2. #2
    Scott Kutz
    Join Date
    Apr 2010
    Posts
    32
    Points
    4
    Answers Provided
    0


    0

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

    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

  3. #3
    David Kelly
    Join Date
    May 2010
    Posts
    34
    Points
    1
    Answers Provided
    0


    0

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

    Quote Originally Posted by skutz View Post
    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.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts