I am trying to convert my old ArcGIS 9.3 (VBA) code to ArcGIS 10 using Visual Basic 2008 Express Edition. So far I have sucessfully created an pop-up window that displays the attributes of a selected feature in text boxes on the form.
I added a reference to the editor and made some adjustments to my code. My form still crashes when I try to press the button. Am I missing something or am I just referencing the attribute table in correctly?
THANKS!!!
Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click
pMxDoc = My.ArcMap.Document
Dim pMap As IMap
pMap = pMxDoc.FocusMap
Dim pFLayer As IFeatureSelection
Dim Count As Integer
'Get a reference to the editor.
Dim editorUID As ESRI.ArcGIS.esriSystem.UID
editorUID = New ESRI.ArcGIS.esriSystem.UID
editorUID.Value = "esriEditor.Editor"
Dim editor As IEditor
editor = My.ArcMap.Application.FindExtensionByCLSID(editorUID)
'Get FeatureLayer
pFLayer = pMap.Layer(Count)
Dim pFCursor As IFeatureCursor = Nothing
pFLayer.SelectionSet.Search(Nothing, False, pFCursor)
Dim pF As IFeature
pF = pFCursor.NextFeature
'Get Dataset from FeatureLayer
Dim pEditDataset As IDataset
pEditDataset = pFLayer
'If not editing, start editing dataset's Workspace
If editor.EditState <> esriEditState.esriStateEditing Then
editor.StartEditing(pEditDataset.Workspace)
End If
'Initialize first (only) feature
Dim pFeat As IFeature
pFeat = pFLayer.NextFeature
'Update attributes with user input
pFeat.Value(pFeat.Fields.FindField("YEAR")) = txtPrjYear.Text
pFeat.Value(pFeat.Fields.FindField("PROJECTYPE")) = txtPrjType.Text
pFeat.Value(pFeat.Fields.FindField("LOCATION")) = txtLocation.Text
pFeat.Value(pFeat.Fields.FindField("AGENCY")) = txtAgency.Text
pFeat.Value(pFeat.Fields.FindField("DESCRIPTION")) = txtDescrip.Text
pFeat.Value(pFeat.Fields.FindField("COST")) = txtCost.Text
pFeat.Value(pFeat.Fields.FindField("DATEEDITED")) = txtDate.Text
pFeat.Value(pFeat.Fields.FindField("USEREDITED")) = txtUser.Text
'Stop editing and save edits
editor.StopEditing(True)
'Refresh map
pMxDoc.ActiveView.Refresh()
'Close form
Me.Close()
End Sub