Dim pCalc As GeoDatabaseUI.ICalculator = New GeoDatabaseUI.Calculator() pCalc.Expression = "[FID] * 2"
Dim pCalc As GeoDatabaseUI.ICalculator = New GeoDatabaseUI.Calculator() pCalc.Expression = "!FID! * 2"
Below is a workaround that compensates for the lack of being able to specify the parser in ICalculator. It takes advantage of IGeoProcessor and the CalculateField_management geoprocessing tool. The parser or expression_type argument of that tool can be used to specify Python as the parser.
'(To test the below VBA code, create a UIButton in VBA and add the code inside the Click event handler of your new UIButton. The second procedure, ReturnMessages(), is called into action by the first procedure towards the very end, but may not be necessary if you do not want to read the messages of the geoprocessing results. Change the first parameter as needed to reflect the correct location of your input table.)Private Sub UIButtonControl1_Click() 'Create the Geoprocessor Dim pGp As IGeoProcessor Set pGp = New GeoProcessor 'Set Overwriteoutput to True pGp.OverwriteOutput = True 'Add the custom toolbox containing the model tool 'pGp.AddToolbox "C:\CustomTools\custom.tbx" 'Create the Parameter array Dim pParamArray As IVariantArray Set pParamArray = New VarArray 'Populate array of parameters 'First Parameter: in_table (e.g. File GDB feature class) pParamArray.Add "C:\Incidents\845875\Converted_GDB931\downgradedFGDB.gdb\Main_931" 'Second Parameter: field on which to calculate pParamArray.Add "LastField" 'Third Parameter: expression pParamArray.Add "math.log1p(!SumOfConcentrations!)" 'Fourth Parameter: expression_type (Optional) !!! !!! !!! !!! !!! pParamArray.Add "PYTHON_9.3" Dim pResult As IGeoProcessorResult 'Execute the Model tool Set pResult = pGp.Execute("CalculateField_management", pParamArray, Nothing) 'Get the returned tool messages ReturnMessages pResult End Sub Public Sub ReturnMessages(ByVal messages As IGeoProcessorResult) Dim i As Long Dim message As String For i = 0 To messages.MessageCount - 1 message = messages.GetMessage(i) Debug.Print message Next End Sub