AO入门之创建一个dbf文件 的方法
Public FunctioncreateDBF(strNameAs String, _ strFolderAs String, _OptionalpFieldsAsIFields)AsITable' 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 GoToEH' Open the WorkspaceDimpFWSAsIFeatureWorkspaceDimpWorkspaceFactoryAsIWorkspaceFactoryDimfs as objectDimpFieldsEditAsIFieldsEditDimpFieldEditAsIFieldEditDimpFieldAsIFieldSetpWorkspaceFactory =NewShapefileWorkspaceFactorySetfs = CreateObject("Scripting.FileSystemObject")If Notfs.FolderExists(strFolder)ThenMsgBox "Folder does not exist: " & vbCr & strFolderExit Function End If SetpFWS = pWorkspaceFactory.OpenFromFile(strFolder, 0)' if a fields collection is not passed in then create oneIfpFieldsIs Nothing Then' create the fields used by our objectSetpFields =NewFieldsSetpFieldsEdit = pFields pFieldsEdit.FieldCount = 1'Create text FieldSetpField =NewFieldSetpFieldEdit = pFieldWithpFieldEdit .Length = 30 .Name = "TextField" .Type = esriFieldTypeStringEnd With SetpFieldsEdit.Field(0) = pFieldEnd If SetcreateDBF = pFWS.CreateTable(strName, pFields,Nothing,Nothing, "")Exit FunctionEH: MsgBox Err.Description, vbInformation, "createDBF"End Function使用注意:
'参数strName和strFolder是必需的。 '要注意在这个方法中,pFieldsEdit.FieldCount必须和后面添加的field数目相同,否则会出现错误。 '在一些项目中,会要求对已有的属性表进行统计分析,生成统计结果,如果要求是dbf格式, '大家可以用这个方法生成统计结果表。 '第一、第二个参数是必须的。同样,大家可以根据需要,改写此方法,参数中可以传入如FieldCount '等在调用此方法前,已经经过计算得到的一些值。
本文地址:http://www.45fan.com/a/question/69803.html
