andrewhayden

Optional parameters must specify a default value.

Discussion created by andrewhayden on Sep 20, 2011
Latest reply on Sep 21, 2011 by agray1
I'm modifying the createDBF developer sample function with VB 2008 Express (Create a new DBASE file).  I think I've got everything worked out except for dealing with an "Optional parameters must specify a default value" error that comes up, in regard to the Optional pFields parameter.  Can anyone get me on track with what the default might look like?
Optional pFields As IFields = ???
 


Public Function createDBF(strName As String, strFolder As String, Optional pFields As IFields) As ITable
        ' createDBF: simple function to create a DBASE file.
        ' note: the name of the DBASE file should not contain the .dbf extension
        '
        On Error GoTo EH

        ' Open the Workspace
        Dim pFWS As IFeatureWorkspace
        Dim pWorkspaceFactory As IWorkspaceFactory
        Dim fs As Object
        Dim pFieldsEdit As IFieldsEdit
        Dim pFieldEdit As IFieldEdit
        Dim pField As IField

        pWorkspaceFactory = New ShapefileWorkspaceFactory
        fs = CreateObject("Scripting.FileSystemObject")
        If Not fs.FolderExists(strFolder) Then
            MsgBox("Folder does not exist: " & vbCr & strFolder)
            Exit Function
        End If

        pFWS = pWorkspaceFactory.OpenFromFile(strFolder, 0)

        ' if a fields collection is not passed in then create one
        If pFields Is Nothing Then
            ' create the fields used by our object
            pFields = New Fields
            pFieldsEdit = pFields
            pFieldsEdit.FieldCount_2 = 1

            'Create text Field
            pField = New Field
            pFieldEdit = pField
            With pFieldEdit
                .Length_2 = 30
                .Name_2 = "TextField"
                .Type_2 = esriFieldType.esriFieldTypeString
            End With
            pFieldsEdit.Field_2(0) = pField
        End If

        createDBF = pFWS.CreateTable(strName, pFields, Nothing, Nothing, "")

        Exit Function
EH:
        MsgBox(Err.Description, vbInformation, "createDBF")

    End Function

Outcomes