00:04In this presentation, I'm going to convert a VB6 class that implements ICommand...
00:10...into VB.NET base class called, "Base Command."
00:13I'm going to start here at the Resource Center...
00:15...in this VB6 sample called "PanZoom Commands."
00:19Inside here, there's about 12 commands.
00:21I'm going to work with the FixedZoomIn command.
00:23It's a VB6 command, I'm going to convert it to VB.NET.
00:28I've downloaded it to my machine; the sample comes in as a Zip file.
00:31I unpack it -- it become a Visual Basic 6 project with a bunch of classes in it.
00:37As I open VB6, I can see my class with all the others.
00:42And when I look at its code, I see that it implements ICommand, so there's a whole...
00:47...bunch of property procedures in here implementing all the members.
00:51There's a couple of OnCreate, OnClick event at the end here.
00:57I'm really interested in the OnClick event and all of its code -- this is my business logic.
01:02So here I'm going to go and bring up Visual Studio 2008.
01:05And I'm going to start making my VB.NET project.
01:08There's some ArcGIS integration here, where I have Desktop and Engine loaded...
01:13...and here I can build an ArcMap class library.
01:16So here, I'm going to build RobsCommand.
01:20And we'll go ahead and let it create this project for us.
01:24It's going to ask me for some references.
01:26I'm not going to set these now.
01:27I'll set them later on and discuss the settings a little bit later on.
01:32I'm going to delete the initial class that it builds...
01:36...and what I'm going to do here is make my own.
01:39So I'm going to go to Add and add a new class in over here.
01:43When I do this adding of a class, I get another set of templates from ArcGIS...
01:48...and these templates are base classes; I want base command.
01:54And mine is called FixedZoom.
02:01We'll add that in here.
02:02Now it wants to know -- for this command, is it going to work in...
02:05...ArcGlobe, or ArcScene, or ArcCatalog?
02:07And mine is an ArcMap command so I'll add it in over there.
02:11You do get a .bmp file, but the one you get is kind of silly there...
02:16...so I'm going to add in one of my own.
02:18Not really one of my own, but an existing item.
02:22And here I'm going to go to the download folder...
02:24...where I downloaded the PanZoom sample.
02:27And there's a resource folder there with all the .bmp files for all those commands.
02:32So I'll grab the one I like here for the ZoomIn.
02:36And I'm going to make a change over here for the ZoomIn .bmp.
02:41Instead of it being a Build Action of Content, I'm going to build it as an embedded resource...
02:47...so that I don't have a file dependency sitting out there.
02:51I'm going to grab just the text name of this command; and then my VB project...
02:57...I want to come in here to the setting of the .bmp file, .bmp property.
03:05All right, so I've got that prepared.
03:08My other properties here are all text strings.
03:11Instead of property procedures, they're text strings...
03:13...because here, we have a BaseCommand, a BaseClass.
03:17We're inheriting from BaseCommand.
03:19BaseCommand internally implements ICommand.
03:24So here, we don't see all those property procedures -- just property settings.
03:28So I can delete those, and I've got some prepared here that I've typed in...
03:32...and then you don't have to watch me fumble through a lot of poor typing skills.
03:39All right, so now I've got the cosmetic part done.
03:42The next thing I need to do is get the business logic from VB6.
03:45So here's all that code in the OnClick event.
03:50I'm going to copy and paste it over to my Visual Studio's OnClick event for this button.
03:57Oops, I've gone down a little farther than I wanted to here.
04:00And you can see I have a couple of references missing that I didn't add in earlier.
04:04I want to show you here with IActiveView and IEnvelope.
04:08What if this is somebody else's code and you don't know that IActiveView comes from...
04:12...Esri ArcGIS Carto?
04:14You can use the Library Locator.
04:17Grab one of the interface names in question, type it in here, and search.
04:21And here, it will give you the .NET assembly or namespace that you need to reference.
04:27Well, let's reference those now.
04:28I'll go to the project and add ArcGIS Reference.
04:32In the Desktop ArcMap there, there's ArcGIS Carto.
04:36I know I'm going to need Display...
04:37...so I'll add it in also and then geometry was that other one for IEnvelope.
04:43I finished there; I need to add one more reference that didn't appear in the listing...
04:49...there, but it's a reference to the ArcGIS controls.
04:56I need to get those controls in here...
05:01...as I add in the reference to those controls.
05:03Let me scroll down here to -- one more -- and get controls in here.
05:09The references are still blue.
05:11I get to come up here and do imports.
05:14I need to import those name spaces, and I'm going to get those from...
05:20...exactly, I've typed them in already, so I don't have to worry about any typing mistakes.
05:25All right, now the last thing I need to do is...
05:29...I've got another blue area here that describes my hook.
05:34And I'm going to need to set up a reference to the hook, so I'm just going to copy and...
05:37...paste some more code from VB.
05:41There's a hook helper variable declared here.
05:44I'm going to get that hook helper variable and paste it in.
05:49And then just to go on the quicker side, there's two others that I need...
05:53...and I'm going to paste them into the OnCreate here.
05:57And I've got some comments as to where I grabbed these two lines of code.
06:02One is from initial highs in VB 6 and one is from the VB 6 OnCreate.
06:07So I've got all my code in here, I'm going to go ahead and build this solution.
06:11It looks like the build worked properly; now, I'm going to go to ArcMap.
06:15You can see all the counties that I've been to here; the green ones are all my...
06:19...counties that I've visited
06:21Here, you see the ArcGIS commands for Rob; the FixedZoomIn command.
06:25I'll drag it up here; you can see it looks like the same one on the Tools toolbar.
06:30If I click it a few times, it zooms in on the map.
06:32So we've had a very successful conversion here from VB 6 to VB.NET...
06:37...using the base command.
06:40I could follow this same process from my other 11 commands there in the sample...
06:45...and simply take their business logic and move it over to a new base command.
06:50Well, on behalf of Esri, I'm Rob Burke.
06:53And I hope you've enjoyed the presentation -- so long and tanks for listening!
ArcGIS Application Migration: Converting Commands from VB6 to VB.NET
In this video, Rob Burke from Esri Educational Services provides a walk-through for how to convert a command class that implements ICommand from a VB6 project to a .NET project using Microsoft Visual Studio 2008.
- Recorded: May 13th, 2010
- Runtime: 07:03
- Views: 733
- Published: Aug 18th, 2011
- Night Mode (Off)Automatically dim the web site while the video is playing. A few seconds after you start watching the video and stop moving your mouse, your screen will dim. You can auto save this option if you login.
- HTML5 Video (Off) Play videos using HTML5 Video instead of flash. A modern web browser is required to view videos using HTML5.