Select to view content in your preferred language

Conversion: VBA to .NET ThisDocument

1967
3
03-15-2010 11:35 AM
NathanAmboy
Deactivated User
The following code was in my "ThisDocument" in VBA.  I've exported it to it's own .NET Class. How do I set pMxdoc to my Arcmap session in the code - it has null value for now?  And what is the best way to Dim forms?  I've seen three ways: as "Object"; as "Form1"; as System.Windows.Forms.Form - also null value for now ....

    Public Sub DYO_Click()
        Dim DYO_UserForm As Form1
        Dim pMxdoc As ESRI.ArcGIS.ArcMapUI.IMxDocument
        Dim pMap As ESRI.ArcGIS.Carto.IMap = pMxdoc.FocusMap
        DYO_UserForm.Show()
    End Sub
0 Kudos
3 Replies
G__Venkata_VijayaKumar
Occasional Contributor
Where is this code in the Dot net class. Are you creating a button or a tool?
0 Kudos
DevdattaTengshe
Deactivated User
The following code was in my "ThisDocument" in VBA.  I've exported it to it's own .NET Class. How do I set pMxdoc to my Arcmap session in the code - it has null value for now? 


The variable "ThisDocument" does not exist when customizing through .NET. What you need to do, is to get it through the application. If you have a custom command button/tool, then you probably have a variable called m_app of the type IApplication, which was initialized on the 'On create' event.  you just need:
to use the IApplication.Document property to get to the Document from which you can cast to IMxDocument



And what is the best way to Dim forms?  I've seen three ways: as "Object"; as "Form1"; as System.Windows.Forms.Form - also null value for now ....


Generally we dim & open a form like this:
Dim frm as Myform=new Myform()                'Myform is the name of your form
frm.show
0 Kudos
MikeLouwrens
Frequent Contributor
The following code was in my "ThisDocument" in VBA. I've exported it to it's own .NET Class. How do I set pMxdoc to my Arcmap session in the code - it has null value for now?


This is what I do to replace the ThisDocument VBA lines...
Replace this (or similar) from VBA:
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument

With this in .Net:
Dim pDoc As IDocument = m_application.Document
Dim pMxDoc As IMxDocument = CType(pDoc, IMxDocument)

It might not be the right/best way to do it, but it's worked for me everytime I've used it.

HTH
Mike.
0 Kudos