Using a FeatureCursor with ISelectionSet.Search with Option Strict On

809
2
04-11-2012 12:33 PM
FrançoisRobitaille
New Contributor
Hi everyone,

I'm having this problem when I try to convert this simple Function from VBA to VB.Net with The "Option Strict On"
I Wish to use a FeatureCursor to retreive all the Features selected in a FeatureLayer.  In VBA, we were able to pass a FeatureCursor to the Search Method of ISelectionSet.  In .Net, with Option Strict On, this is not possible anymore.  We have to pass a Cursor (otherwise a CType conversion will be requiered, wich won't work anyway!)

So my question is how do I access the Feature if I can only use a Cursor?
Please, see the attached code.

TIA for your help!
F.
0 Kudos
2 Replies
KevinBupp
New Contributor III
All you need to do is cast your Cursor.NextRow as an IFeature:
      Dim SelFeature As IFeature = Nothing
      Dim Cursor As ICursor = Nothing
      SelSet.Search(Nothing, True, Cursor)
      SelFeature = CType(Cursor.NextRow, IFeature)


Note the following excerpt from here:
By default in VB, casting is automatically done for you when you assign objects to variables. The objects are then automatically casted to the variables' type.

This behavior can be influenced by an option line on top of your code file:
Option Strict On
Option Strict Off

When on, casting is strict and not automatic.
0 Kudos
FrançoisRobitaille
New Contributor
That's great!

It works just fine!  Thank you!  I'll be more carefull with my casting in the future!

Thanx again!
F.
0 Kudos