Object Variable Error - - Please Help!
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Object Variable Error - - Please Help!

  1. #1
    Join Date
    Oct 2009
    Posts
    0

    Object Variable Error - - Please Help!

    I've created a form in ArcMap that allows you to fill in parcel data. I have two feature classes, To-Do Parcels (unsurveyed) and Surveyed Parcels. I want to be able to click on a To-Do parcel, fill in the form, hit save, and add that parcel feature to the Surveyed Parcels feature class. Here is what I have so far in my code. Now I am getting the Object Variable Error, and have no idea why, please help!

    Code:
    Private Sub cmdCancel_Click()
        frmSurvey.Hide
    End Sub
    Public Sub LoadFeatures()
      Dim pToDoAreaFClass As IFeatureClass
      Dim pSurveyedAreaFClass As IFeatureClass
      Dim pSearchFeatureCursor As IFeatureCursor
      Dim pFeature As IFeature
      Dim pInsertFeatureBuffer As IFeatureBuffer
      Dim pInsertFeatureCursor As IFeatureCursor
      Dim NewFeatureCount As Integer
      
      On Error GoTo ErrorHandler
      
      'Open shapefile where new features will be written to
      'For simplicity, sample does not contain code to create a new shapefile
      Set pSurveyedAreaFClass = OpenFeatureClass("E:\GEOG423\Projects\Group\Data", "Surveyed_Areas")
      If pSurveyedAreaFClass Is Nothing Then Exit Sub
      Set pInsertFeatureCursor = pSurveyedAreaFClass.Insert(True)
      Set pInsertFeatureBuffer = pSurveyedAreaFClass.CreateFeatureBuffer
      
      'Open shapefile containing the features that will be copied
      Set pToDoAreaFClass = OpenFeatureClass("E:\GEOG423\Projects\Group\Data", "To_Do_January_-_August_2009")
      If pToDoAreaFClass Is Nothing Then Exit Sub
    
      'Find selected feature in ToDoAreaFClass
      Set pSearchFeatureCursor = pToDoAreaFClass.Search(justOne, True)
      Set pFeature = pSearchFeatureCursor.NextFeature
      Do While Not pFeature Is Nothing
        'Add the original feature's geometry to the feature buffer
        Set pInsertFeatureBuffer.Shape = pFeature.Shape
        'Add all the original feature's fields to the feature buffer
        AddFields pInsertFeatureBuffer, pFeature
        'Insert the feature into the cursor
        pInsertFeatureCursor.InsertFeature pInsertFeatureBuffer
        Set pFeature = pSearchFeatureCursor.NextFeature
    
      Loop
     
      
      Exit Sub 'Exit to avoid error handler
      
    ErrorHandler:
      MsgBox Err.Description
      Resume Next
    End Sub
    
    Private Sub AddFields(pFeatureBuffer As IFeatureBuffer, pFeature As IFeature)
      Dim pRowBuffer As IRowBuffer
      Dim pNewFields As IFields 'fields on target feature class
      Dim pNewField As IField
      Dim pFields As IFields 'fields on original feature class
      Dim pField As IField
      Dim FieldCount As Integer
      Dim NewFieldIndex As Long
      
      'Copy the attributes of the orig feature the new feature
      Set pRowBuffer = pFeatureBuffer
      Set pNewFields = pRowBuffer.Fields
      
      Set pFields = pFeature.Fields
      If Not pField.Type = esriFieldTypeGeometry And Not pField.Type = esriFieldTypeOID _
          And pField.Editable Then
            NewFieldIndex = pNewFields.FindField(pField.Name)
            If Not NewFieldIndex = -1 Then
              pFeatureBuffer.Value(NewFieldIndex) = pFeature.Value(FieldCount)
            End If
      End If
        
        pFeature.Value(2) = txtMAPPLAT.Text
        pFeature.Value(3) = txtREALMAPCOD.Text
        pFeature.Value(4) = Val(txtREALSTNO.Text)
        pFeature.Value(5) = txtREALSTNAME.Text
        pFeature.Value(6) = txtREALAPTNO.Text
        pFeature.Value(7) = txtSUBNAME.Text
        pFeature.Value(8) = txtNAMNAME.Text
        pFeature.Value(9) = txtNAMADDR.Text
        pFeature.Value(10) = txtNAMCITY.Text
        pFeature.Value(11) = txtNAMST.Text
        pFeature.Value(12) = Val(txtNAMZIP.Text)
        pFeature.Value(13) = Val(txtNAMZIPEXT.Text)
        
        
        
        pFeature.Value(17) = txtSDDISTRICT.Text
        
        pFeature.Value(19) = txtSURVEY_NUM.Text
        pFeature.Value(20) = txtGROUP_NUM.Text
        pFeature.Value(21) = txtHIST_NAME.Text
        pFeature.Value(22) = txtOTHER_NAME.Text
        pFeature.Value(23) = Val(txtSTREET_NUM.Text)
        pFeature.Value(24) = txtSTREET.Text
        pFeature.Value(25) = txtOLD_ADDRES.Text
        pFeature.Value(26) = txtCITY_COMM.Text
        pFeature.Value(27) = txtNR_DESIG.Text
        pFeature.Value(28) = txtLOCAL_DESI.Text
        pFeature.Value(29) = txtUSGS_MAPNU.Text
        pFeature.Value(30) = txtPVA_MAPNUM.Text
        pFeature.Value(31) = txtORIG_USE.Text
        pFeature.Value(32) = txtCUR_USE.Text
        pFeature.Value(33) = txtDOC.Text
        pFeature.Value(34) = txtSTYLE.Text
        pFeature.Value(35) = txtDEMOED.Text
        pFeature.Value(36) = txtNOTES.Text
    End Sub
    
    Public Function OpenFeatureClass(strWorkspace As String, strFeatureClass As String) As IFeatureClass
      On Error GoTo ErrorHandler
      Dim pShpWorkspaceName As IWorkspaceName
      Dim pDatasetName As IDatasetName
      Dim pName As IName
      
      'Create the workspace name object
      Set pShpWorkspaceName = New WorkspaceName
      pShpWorkspaceName.PathName = strWorkspace
      pShpWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesFile.shapefileworkspacefactory.1"
      
      'Create the feature class name object
      Set pDatasetName = New FeatureClassName
      pDatasetName.Name = strFeatureClass
      Set pDatasetName.WorkspaceName = pShpWorkspaceName
      
      'Open the feature class
      Set pName = pDatasetName
      Set OpenFeatureClass = pName.Open
      
      Exit Function
      
    ErrorHandler:
      Set OpenFeatureClass = Nothing
    End Function
          
    Private Sub cmdSave_Click()
        Call LoadFeatures
    End Sub

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,990

    Re: Object Variable Error - - Please Help!

    We don't know about ArcMap, or your code. You could post a few lines surrounding where the error occurs, along with the error text and error number. Then we might be able to help
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,722

    Re: Object Variable Error - - Please Help!

    If you want help about a distinct error, you have to at least mark the line of code where the error occurs. None of us can run your code to find that out, because everything else of the program including the data is missing.
    As David sayd: post a few lines before and after the lines which fires the error and tell exactly what the error message is saying.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center