Public Sub TheMacro() Dim pMxDocument As IMxDocument Set pMxDocument = ThisDocument Dim pFeatureLayer As IFeatureLayer Set pFeatureLayer = pMxDocument.FocusMap.Layer(0) Dim pDataset As IDataset Set pDataset = pFeatureLayer.FeatureClass Dim pFields As IFields Set pFields = ValidateFields(pDataset.Workspace, pFeatureLayer.FeatureClass.Fields) End Sub Public Function ValidateFields(pWorkspace As IWorkspace, pFields As IFields) As IFields 'Create a new field checker and validate the fields. Dim pFieldChecker As IFieldChecker Set pFieldChecker = New FieldChecker Dim pValidatedFields As IFields Dim pEnumFieldError As IEnumFieldError Set pFieldChecker.ValidateWorkspace = pWorkspace pFieldChecker.Validate pFields, pEnumFieldError, pValidatedFields 'pEnumFieldError.Reset Dim pFieldError As IFieldError Dim pField As IField 'Display any errors that were found. If Not pEnumFieldError Is Nothing Then Set pFieldError = pEnumFieldError.Next Do Until pFieldError Is Nothing Set pField = pFields.Field(pFieldError.FieldIndex) Debug.Print pField.Name, pFieldError.FieldError Set pFieldError = pEnumFieldError.Next Loop End If ' Dim pSqlKeywordDictionary As ISqlKeywordDictionary ' Set pSqlKeywordDictionary = pFieldChecker.ValidateDictionary ' ' Dim lngCount As Long ' Dim blnResult As Boolean ' blnResult = pSqlKeywordDictionary.Count(lngCount) ' ' ' ' Debug.Print lngCount ' ' Dim i As Long ' For i = 0 To pSqlKeywordDictionary.Count(lngCount) - 1 ' Debug.Print pSqlKeywordDictionary.Name ' Next i ' Set ValidateFields = pValidatedFields End Function
IDataStatics の利用
2016/9/1 (木)