Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have some code I wrote in 9.3 that (mostly) works in version 10. I have a UIToolControl that buffers a user-input point based on a mouse click - nearly identical to the sample.

This used to work fine. Now I get an error - "Invalid use of New keyword" when the code tries to create a new Point from which to buffer.

Both the sample and my code work fine in a blank MXD (I have to comment out the CountElements.CountElementsInMap line which refers to another procedure), but not in this one.

Is there a conflict between some other variable that may be hanging out in memory space? I cannot find one and this fails even if it is the first thing I do.

Private Sub UIToolControl1_MouseDown(ByVal button As Long, ByVal shift As Long, _
                                     ByVal x As Long, ByVal y As Long)
    'Stop
    Dim pDoc As IMxDocument
    Dim pMap As IMap
    Dim pAV As IActiveView
    Set pDoc = ThisDocument
    Set pMap = pDoc.FocusMap
    Set pAV = pDoc.FocusMap
    Dim pPoint As IPoint
    Set pPoint = New Point  'Fails right here - Invalid use of New keyword
    Set pPoint = pDoc.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y)
    Dim pGC  As IGraphicsContainer
    Dim pGCS As IGraphicsContainerSelect
    Dim pElem As IElement
    Dim pElemProp As IElementProperties
    Set pGC = pMap
    Set pElem = New MarkerElement
    pElem.Geometry = pPoint
    Set pElemProp = pElem
    pElemProp.Name = "BufferPoint"
    pGC.AddElement pElem, 0
    Set pGCS = pMap
    pGCS.SelectElement pElem
    'Stop
    'CountElements.CountElementsInMap
    Dim pCmdBar As ICommandBar
    Dim pCmdItem As ICommandItem
    Dim pUID As New UID
    Set pCmdItem = Document.CommandBars.Find(ArcID.PageLayout_SelectTool)
    Set Document.Parent.CurrentTool = pCmdItem
    'pAV.Refresh
End Sub

Thanks in advance for any help! Dan

share|improve this question
1  
did you try fully qualifying the point? (Set pPoint = New esriGeometry.Point) –  Kirk Kuykendall Feb 9 '12 at 18:07
    
Also standard notice that VBA is not supported at 10.1 so you might as well start thinking of converting it to an add-in or arcpy. –  blah238 Feb 9 '12 at 18:12
    
Think I've figured it out. Certain objects have changed between 9.3 and 10, such as accessing Application/Document, etc. I think in some of the startup scripts I still have old and new objects conflicting. Thus in THIS script, I have to fully qualify IPoint...whereas in other parts of the project I do not. The code had worked until yesterday. Looks like I have a lot of tidying up to do! Thanks Kirk! And yes, blah238, I am aware of the termination of VBA in future releases. My office is slow to adopt so I've got a couple of years! But we're working on it. Just no time on this project. –  Dan Shaffer Feb 9 '12 at 19:24
    
I guess this can be considered closed! –  Dan Shaffer Feb 9 '12 at 19:26
    
In VB .NET it's pPoint = new PointClass(), perhaps it's the same in VBA. –  Stephen Quan Feb 10 '12 at 10:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.