converting vba to .net

3278
8
01-24-2011 09:19 AM
maxsteinbrenner
New Contributor II
I am sure many of you are in the same boat:

I am just starting to try to convert my vba code to .net. I have begun with a very simple routine that basically just adds a start and end point to a route features we frequently make here at work.

I am having a difficult time figuring out what to do when things are labeled undeclared or undefined in Visual Studio.

For example here is a piece of the code below that defines the start point text and alignment. I have put the Visual Studio errors in the comments to the right of the variables:

   '+++ Define the START Text Symbol
        Dim pTextSymbol As ITextSymbol
        pTextSymbol = New TextSymbol


        pTextSymbol.HorizontalAlignment = esriTHARight 'not declared
        pTextSymbol.VerticalAlignment = esriTVABottom 'not declared
 

        'FONT/SIZE
        Dim myFont As IFontDisp 'not defined
        myFont = New StdFont 'not defined
        myFont.Name = Arial 'not declared
        myFont.size = 18
        myFont.Bold = True
        pTextSymbol.Font = myFont 'Reference required to assembly blahblah

        'COLOR
        Dim pRGBColor As IRgbColor
        pRGBColor = New RgbColor
        pRGBColor.Red = 163
        pRGBColor.Green = 255
        pRGBColor.Blue = 115
        pTextSymbol.Color = pRGBColor

        'HALO
        Dim pMask As IMask
        pMask = pTextSymbol
        pMask.MaskStyle = esriMSHalo 'not declared
        pMask.MaskSize = 0.5
        pTextSymbol = pMask


If someone could help me to figure out how to redefine and redeclare these things so they would work in Visual Studio I would be very appreciative. There seems to be very little documentation regarding this topics like this anywhere on the interent currently but hopefully I am just missing something obvious and one of you can get me started down the right path.

thanks,

max
0 Kudos
8 Replies
RuchiraWelikala
Occasional Contributor
For the Horizonal and vertical alignment, the esriTHARight should begin with
esriTextHorizontalAlignment
so it would be
esriTextHorizontalAlignment.esriTHARight


Make sure the proper assemblies are loaded.  If an interface is not recognized by the Visual Studio, it usually means it isn't added as a reference. 

Refer to this link for help with the IFontDisp stuff:
http://edndoc.esri.com/arcobjects/9.2/NET/ca849e1d-5da3-4b64-90da-7a0cad7804f5.htm

For the esriMSHALO you need to import the ESRI.ArcGIS.Display assembly into your project.
It's a constant in esriMarkStyle category.
So the code would be
esriMarkStyle.esriMSHalo


Other than that, you need to seek out documentation on how to migrate from VBA to VB.NET (Visual Studio).
0 Kudos
JeffreyHamblin
New Contributor III
As mentioned in a prior post, you need references to assemblies. And to use types without full qualification, you need to "use" the correct namespaces.

I put together a little tutorial on converting VBA to a C# Add-in. Since you are working in VB.net, it is a little different. But this particular short video may give you a shortcut for adding assemblies in Visual Studio as you convert your code using the Object Browser (I assume it functions the same when using VB.net):

http://gis.qtools.com/tutorials/vba_to_cs/video/CS2008_ConvertVBA_Demo_pt03.swf.html (1 minute flash video)

The full tutorial is here:
http://gis.qtools.com/blog/tutorials/vba-to-c-add-in/


-Jeff
0 Kudos
maxsteinbrenner
New Contributor II
Other than that, you need to seek out documentation on how to migrate from VBA to VB.NET (Visual Studio).



thanks for the pointers. i do have the ESRI.ArcGIS.Display assembly loaded, that took care of ITextSymbol


if you have any pointers on the type of documentation you describe i'd appreciate it. coming from VBA where you find code snippets already written to do pretty much anything GIS related, the transition to vb.net is pretty harsh so far.
0 Kudos
RuchiraWelikala
Occasional Contributor
Well the main thing is "hooking" the ArcMap document or the Application so you can work with the current document.  In VBA, this is done by "ThisDocument".  In VB.NET, ESRI has set up neat little snippets to grab the document from the application.
Refer to this link for Snippet Help:
http://edndoc.esri.com/arcobjects/9.2/NET/040b30ea-16e1-4dee-af9d-e2157c7d4ddb.htm

This is an index of all the snippets available to you through the VS (Visual Studio) interface:
http://resources.esri.com/help/9.3/ArcGISDesktop/dotnet/snippetreference.htm

For other information, refer to this link:
http://resources.esri.com/help/9.3/ArcGISDesktop/dotnet/concepts_start.htm
0 Kudos
TomGiles
New Contributor
As mentioned in a prior post, you need references to assemblies. And to use types without full qualification, you need to "use" the correct namespaces.

I put together a little tutorial on converting VBA to a C# Add-in. Since you are working in VB.net, it is a little different. But this particular short video may give you a shortcut for adding assemblies in Visual Studio as you convert your code using the Object Browser (I assume it functions the same when using VB.net):

http://gis.qtools.com/tutorials/vba_to_cs/video/CS2008_ConvertVBA_Demo_pt03.swf.html (1 minute flash video)

The full tutorial is here:
http://gis.qtools.com/blog/tutorials/vba-to-c-add-in/


-Jeff



Hi Jeff,

A great tutorial site you have, thanks from all of us!

I was following your tutorial for adding a toolbar (I have never attempted that before) and I came across an error on my system I was hoping you could help me with. One caveat, I am using VB, not C#. I am assuming it is the same (although I could be wrong).

When I attempt step #4, Add --> New Item, and then select 'Add-in component', I get the error message:

"Invalid ArcGIS Add-In Project. Unable to resolve the Add-in host from the configuration xml file."

Have you ever seen that?

Thanks for your help, it is much appreciated.

Cheers,
Tom
0 Kudos
JeffreyHamblin
New Contributor III
Hi Tom,

I have not encountered that error before. I also assume the steps would be the same for a VB.NET project.

Prior to attempting to add the toolbar, did you create an ArcMap Add-In project with a single button?

Looking at the error message, it might help if you paste the contents of the Config.esriaddinx file here so we can take a look at it.

-Jeff
0 Kudos
maxsteinbrenner
New Contributor II
jeff,

that is a great tutorial!

even though i am using .net most of the setup techniques you show are idenitcal between both languages.

max
0 Kudos
AliceShepherd
New Contributor II
I am trying to do the same thing as in the code posted at the start of this thread in .net.  I am getting an error on the line pMask.MaskStyle = esriMaskStyle.esriMSHalo.  The error I get is 'Object variable or With block variable not set' and this on the first part of the line (pMask.MaskStyle). pMask has been declared and set.  Any ideas on how I resolve this error?
0 Kudos