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' Email to me :cnwangyx@163.comOn Error GoTo EH
' Open the WorkspaceDim pFWS As IFeatureWorkspace
Dim pWorkspaceFactory As IWorkspaceFactory
Dim fs as object
Dim pFieldsEdit As IFieldsEdit
Dim pFieldEdit As IFieldEdit
Dim pField As IField
Set pWorkspaceFactory = New ShapefileWorkspaceFactory
Set fs = CreateObject("Scripting.FileSystemObject")
If Not fs.FolderExists(strFolder) Then
MsgBox "Folder does not exist: " & vbCr & strFolder
Exit Function
End If
Set pFWS = pWorkspaceFactory.OpenFromFile(strFolder, 0)
' if a fields collection is not passed in then create oneIf pFields Is Nothing Then' create the fields used by our objectSet pFields = New Fields
Set pFieldsEdit = pFields
pFieldsEdit.FieldCount = 1
'Create text FieldSet pField = New Field
Set pFieldEdit = pField
With pFieldEdit
.Length = 30
.Name = "TextField"
.Type = esriFieldTypeString
End With
Set pFieldsEdit.Field(0) = pField
End If
Set createDBF = pFWS.CreateTable(strName, pFields, Nothing, Nothing, "")
Exit Function
EH:
MsgBox Err.Description, vbInformation, "createDBF"
End Function
使用注意:
Public Function createDBF(strName As String, _ strFolder As String, _ Optional pFields As IFields) As ITable createDBF: simple function to create a DBAS