Select to view content in your preferred language

Using pCalculator with fields and variables

937
3
06-16-2010 06:28 AM
NelsonBetancourt
Deactivated User
Guys, i'ven experiencing many troubles using the pCalculator with variables, values from a form and fields.  I need that some values from a form, a variable that i previosly have declared and a field perform an aritmethical operation.

Can anyone help me with the sintax in .expression? the code is below

Thanks in advance

Public Sub Cal_perd_hum()
Dim pMxDoc As IMxDocument
    Dim pFeatureLayer As IFeatureLayer
    Dim pFeatureClass As IFeatureClass
    Set pMxDoc = ThisDocument
    Set pFeatureLayer = pMxDoc.FocusMap.Layer(1)
    Set pFeatureClass = pFeatureLayer.FeatureClass
    Dim pFields As IFields
    Dim ii As Integer
    Dim pQueryFilter As IQueryFilter
    Dim pCursor As ICursor
    Dim pCalc As ICalculator
    Set pFeatureLayer = pFeatureLayer
    Set pFeatureClass = pFeatureLayer.FeatureClass
    Set pFields = pFeatureClass.Fields
   
    Dim HL1, HL2, HL3, HL4, HL5 As Double
    Dim HG1, HG2, HG3, HG4, HG5 As Double
    Dim FM1, FM2, FM3, FM4, FM5 As Double
   
   
    'Valores del formulario de heridos leves
   
    HL1 = Val(FrmPerdida.txt_HL1.Text)
    HL2 = Val(FrmPerdida.txt_HL2.Text)
    HL3 = Val(FrmPerdida.txt_HL3.Text)
    HL4 = Val(FrmPerdida.txt_HL4.Text)
    HL5 = Val(FrmPerdida.txt_HL5.Text)
   
    'Valores del formulario de heridos graves
   
    HG1 = Val(FrmPerdida.txt_HG1.Text)
    HG2 = Val(FrmPerdida.txt_HG2.Text)
    HG3 = Val(FrmPerdida.txt_HG3.Text)
    HG4 = Val(FrmPerdida.txt_HG4.Text)
    HG5 = Val(FrmPerdida.txt_HG5.Text)
   
    'Valores del formulario de fallecidos o muertos
   
    FM1 = Val(FrmPerdida.txt_FM1.Text)
    FM2 = Val(FrmPerdida.txt_FM2.Text)
    FM3 = Val(FrmPerdida.txt_FM3.Text)
    FM4 = Val(FrmPerdida.txt_FM4.Text)
    FM5 = Val(FrmPerdida.txt_FM5.Text)
   
   
   
   
   
   
   
    '++++++++++++++++++++++++++++++Calculo del valor a tomar dependiendo del DM para las perdidas+++++++++++++++++++++++++
   
          
     ii = pFields.FindField("Dm")
    'Preparacion del cursor para encontrar el criterio seleccionado.
    Set pQueryFilter = New QueryFilter
    pQueryFilter.WhereClause = "Dm >= DC1 AND Dm <= DC2"
    Set pCursor = pFeatureClass.Update(pQueryFilter, True)
    ' Uso del cursor para calcular el valor.
    Set pCalc = New Calculator
    With pCalc
        Set .Cursor = pCursor
           'here is when the code crash
            '.Expression = " FM5 * [POBLACION] / FrmPerdida.txt_FM4.Text"
            .Field = "Pfm"
        End With
        pCalc.calculate
       
       
       End Sub
0 Kudos
3 Replies
JamesCrandall
MVP Frequent Contributor
This is untested and I've not really worked with the Calculator much (if at all), but you could try the following:

Instead of,

'here is when the code crash
'.Expression = " FM5 * [POBLACION] / FrmPerdida.txt_FM4.Text"


Try,

.
Expression = FM5 & " * [POBLACION] / " & FM4
0 Kudos
NelsonBetancourt
Deactivated User
Thanks for the response, there is an error when the code runs:

esri__CalResult = 20 * esri__63 / 0,4857

any suggestions??
0 Kudos
JamesCrandall
MVP Frequent Contributor
Thanks for the response, there is an error when the code runs:

esri__CalResult = 20 * esri__63 / 0,4857

any suggestions??


0,4857?  Are you sure you don't want 0.4857?
0 Kudos