Из VBA в VisualBasi6

0 голосов
спросил 29 Фев, 04 от Гость (210,080 баллов) в категории Программные продукты Esri

Господа, кто сможет объяснить---- следующий код работает в VBA

Dim Mxdoc As IMxDocument
Set Mxdoc = Application.Document
Dim activeview As IActiveView
Set activeview = Mxdoc.ActivatedView
Dim map As IMap
Set map = activeview

map.ClearLayers
Mxdoc.UpdateContents
activeview.Refresh

 

но когда в бэйсике создаю новую кнопку (Icommand) работать  отказывается, кто-нибудь объяснит как заставить это работать и укажет где ошибка????

Заранее спасибо

***********************

' Implement the ICommand interface
Implements ICommand

Dim m_pApp As IApplication
'ArcMap application

 

Private Property Get ICommand_Bitmap() As esriCore.OLE_HANDLE
  ' The VB project contains a form called Form1.
  ' Picture1 is the name of a PictureBox control on the form.
  ' The Picture property of PictureBox1 is set to some bitmap on
  ' your system.
  ICommand_Bitmap = Form1.Picture1.Picture.Handle
End Property

Private Property Get ICommand_Caption() As String
  ' Set the string that appears when the command is used as a
  ' menu item.
  ICommand_Caption = "MyCommand"
End Property

Private Property Get ICommand_Category() As String
  ' Set the category of this command. This determines where the
  ' command appears in the Commands panel of the Customize dialog.
  ICommand_Category = "MyCustomTools"
End Property

Private Property Get ICommand_Checked() As Boolean

End Property

Private Property Get ICommand_Enabled() As Boolean
  ' Add some logic here to specify in what state the application
  ' should be in for the command to be enabled. In this example,
  ' the command is enabled only when there is at least one data
  ' layer loaded in ArcMap.
  Dim pMxDoc As IMxDocument
  Dim pLayerCount As Integer
  'm_pApp is set in OnCreate
  Set pMxDoc = m_pApp.Document
  pLayerCount = pMxDoc.FocusMap.LayerCount
  If pLayerCount > 0 Then
    ICommand_Enabled = True
  Else
    ICommand_Enabled = False
  End If
End Property

Private Property Get ICommand_HelpContextID() As Long
  ICommand_HelpContextID = 1234
End Property

Private Property Get ICommand_HelpFile() As String
  ' If the help file is not registered you may need
  ' to  supply the  full path to the file
  ICommand_HelpFile = "MyHelp.hlp"
End Property

Private Property Get ICommand_Message() As String
  'Set the message string that appears in the statusbar of the
  'application when the mouse passes over the command.
  ICommand_Message = "This is my custom command"
End Property

Private Property Get ICommand_Name() As String
  ' Set the internal name of this command. By convention, this
  ' name string contains the category and caption of the command.
  ICommand_Name = "MyCustomTool_MyCommand"
End Property

Private Sub ICommand_OnClick()
Dim Mxdoc As IMxDocument
Set Mxdoc = Application.Document
Dim activeview As IActiveView
Set activeview = Mxdoc.ActivatedView
Dim map As IMap
Set map = activeview

map.ClearLayers
Mxdoc.UpdateContents
activeview.Refresh
End Sub

Private Sub ICommand_OnCreate(ByVal hook As Object)
  ' The hook argument is a pointer to Application object.
  ' Establish a hook to the application
  Set m_pApp = hook
 
End Sub

Private Property Get ICommand_Tooltip() As String
  'Set the string that appears in the screen tip.
  ICommand_Tooltip = "MyCommand"
End Property

 

1 Ответ

0 голосов
ответил 01 Март, 04 от Alexander1 (32,520 баллов)

Убери из процедуры ICommand_OnClick строку:
Set Mxdoc = Application.Document


и замени её на:
Set Mxdoc = m_pApp.Document

Переменную m_pApp объяви Private

Добро пожаловать на сайт Вопросов и Ответов, где вы можете задавать вопросы по GIS тематике и получать ответы от других членов сообщества.
...