From Cory Eicher

Wednesday, February 22, 2006

1 if ByRef, 2 if ByVal...

ArcGIS Explorer
  • ESRI has posted an FAQ here: ArcGIS Explorer FAQ
  • If you have ArcGIS 9.2 beta (I don't), then you have ArcGIS Explorer. If not, you need to wait for the public beta (March?).
  • Are you registered to attend the upcoming AAG meeting in Chicago? If you are, be sure to see ESRI's David Maguire talk about ArcGIS Explorer (Thurs March 9th): David Maguire AAG Presentation Abstract
  • If you aren't registered for the conference, but you're in the area, you could always attire yourself as a starving graduate student, pop in around 2:45, and sit near the back of the room to hear what David has to say.

Copy/Paste Code Reuse


Ah yes, who hasn't copy pasted code to get a head start. Really there's no problem with this normally, but here's something that happened to me last week, pasting some of my own code no less..

I wrote a few subroutines in ArcMap VBA just to get going. After a bit I brought this code over to VB.NET.

I had a problem bringing one of my subs over, and I didn't figure out what was wrong for a long while. Can you guess what I did?

Well, the top of my sub looked something like this:

Private Sub CalcLineStartEndID(InLayer As IGeoFeatureLayer, _

ByVal LineID As String, _

StartID As Integer, _

EndID As Integer)
And then, towards the end of my sub I did something like this:

StartID = iMinSta

EndID = iMaxSta

So, StartID and EndID are ByRef parameters that I calculate during the sub. Okay, an OO purest would slap me on the wrist, but this is what I felt like doing that day..

Anyway...the problem is, (when you paste this blindly into VB.NET before having your morning cup of coffee or green tea), you get this:

Private CalcLineStartEndID(ByVal InLayer As IGeoFeatureLayer, _

ByVal LineID As String, _

ByVal StartID As Integer, _

ByVal EndID As Integer)


That's right, by default, in VB.NET params are ByVal...so, StartID and EndID become ByVal params, but everything 'pastes in' fine, compiles fine, etc... Just, when you run/test your code, well, things don't work quite the same... Lesson learned.

Talk to you soon,


-Cory

0 Comments:

Post a Comment

<< Home