AO入门之创建一个dbf文件 的方法
Public Function
createDBF(strNameAs String
, _ strFolderAs String
, _Optional
pFieldsAs
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.com
On Error GoTo
EH' Open the Workspace
Dim
pFWSAs
IFeatureWorkspaceDim
pWorkspaceFactoryAs
IWorkspaceFactoryDim
fs as objectDim
pFieldsEditAs
IFieldsEditDim
pFieldEditAs
IFieldEditDim
pFieldAs
IFieldSet
pWorkspaceFactory =New
ShapefileWorkspaceFactorySet
fs = CreateObject("Scripting.FileSystemObject")If Not
fs.FolderExists(strFolder)Then
MsgBox "Folder does not exist: " & vbCr & strFolderExit Function End If Set
pFWS = pWorkspaceFactory.OpenFromFile(strFolder, 0)' if a fields collection is not passed in then create one
If
pFieldsIs Nothing Then
' create the fields used by our object
Set
pFields =New
FieldsSet
pFieldsEdit = pFields pFieldsEdit.FieldCount = 1'Create text Field
Set
pField =New
FieldSet
pFieldEdit = pFieldWith
pFieldEdit .Length = 30 .Name = "TextField" .Type = esriFieldTypeStringEnd With Set
pFieldsEdit.Field(0) = pFieldEnd If Set
createDBF = pFWS.CreateTable(strName, pFields,Nothing
,Nothing
, "")Exit Function
EH: MsgBox Err.Description, vbInformation, "createDBF"End Function
使用注意:
'参数strName和strFolder是必需的。 '要注意在这个方法中,pFieldsEdit.FieldCount必须和后面添加的field数目相同,否则会出现错误。 '在一些项目中,会要求对已有的属性表进行统计分析,生成统计结果,如果要求是dbf格式, '大家可以用这个方法生成统计结果表。 '第一、第二个参数是必须的。同样,大家可以根据需要,改写此方法,参数中可以传入如FieldCount '等在调用此方法前,已经经过计算得到的一些值。
本文地址:http://www.45fan.com/a/question/69803.html