So, I'm following the "Walkthrough: Migrating VB6 to VB.NET for ArcGIS 10" to convert my VB code to .NET (using Visual Studio 2010), and I'm running into this error, "NullReferenceException was unhandled by user code", object reference not set to an instance of an object. It suggests that I use a "new" keyword to create an object instance. I imported all my namespaces under Option Explicit (for this example the GeoDatabase namespace was imported), and turned Option Strict On, and applied all the CType conversions that VS required. Since this walkthrough example is for ArcGIS 10, and I'm using 9.3.1, could this be the issue? I tried to pass the "new" keyword below, but I'm still getting the error. Here is the code. Any input will be greatly appreciated.
If SelectionSet.Count < 1 Then MsgBox("Please select one or more wells", MsgBoxStyle.Critical, "No Selected Wells") Exit Sub 'Retrieve all features 'Set pFeatCursor = pFClass.Search(QFilt, False) Else 'Retrieve just the selected features 'This statement moves the selected features into a feature cursor. All 'subsequent work is done using the feature cursor. 'UPGRADE_WARNING: Couldn't resolve default property of object pFeatCursor. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"' SelectionSet.Search(QFilt, False, CType(FeatCursor, ICursor)) End If 'Get the first feature Dim Feature As IFeature = Nothing Feature = FeatCursor.NextFeature '<<<ERROR
So, I have my ICommand Sub that calls my CreateStick Sub with the new ByRef Cursor As ICursor exception.
Private Sub ICommand_OnClick() Implements ICommand.OnClick Me.CreateStick() End Sub Public Sub CreateStick(ByVal QueryFilter As IQueryFilter, ByVal Recycling As Boolean, _ ByRef Cursor As ICursor)
I stil have two errors on this line:
SelectionSet.Search(QFilt, False, ByRef CType(FeatCursor, ICursor))
ByRef and ICursor are underlined. ByRef = Expression expected and ICursor error = ICursor is a type and cannot be used as an expression.