This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

vb script adding number with empty properties

Hi,

Sorry for the simplicity of my query but I can't find the solution.

On my object, I get 4 number properties which can have a value or not and a "TOTAL" property.

The TOTAL property is autocalculated via VB Script. Simply get the 4 properties and add them.

If one of these properties is not fullfilled it does not work (no value in TOTAL). I tried to check each property value with isempty or isnull and not to add the corresponding property but it does not work too.

Any help would be welcome.

On of my code : 

Option explicit
Dim tot : tot=0

Dim IDQuantitEnStockHeilligenberg : IDQuantitEnStockHeilligenberg = GetPropertyID("PD.QuantitEnStockHeilligenberg")
Dim valQuantitEnStockHeilligenberg : valQuantitEnStockHeilligenberg=PropertyValues.SearchForProperty(IDQuantitEnStockHeilligenberg).TypedValue.Value
if not isempty(valQuantitEnStockHeilligenberg) then tot = tot + valQuantitEnStockHeilligenberg


Dim IDQuantitEnStockRosheim : IDQuantitEnStockRosheim = GetPropertyID("PD.QuantitEnStockRosheim")
Dim valQuantitEnStockRosheim : valQuantitEnStockRosheim=PropertyValues.SearchForProperty(IDQuantitEnStockRosheim).TypedValue.Value
if not isempty(valQuantitEnStockHeilligenberg) then tot = tot + valQuantitEnStockRosheim

Dim IDQuantitEnStockSlestat : IDQuantitEnStockSlestat = GetPropertyID("PD.QuantitEnStockSlestat")
Dim valQuantitEnStockSlestat : valQuantitEnStockSlestat=PropertyValues.SearchForProperty(IDQuantitEnStockSlestat).TypedValue.Value
if not isempty(valQuantitEnStockHeilligenberg) then tot = tot + valQuantitEnStockSlestat

Dim IDQuantitEnStockBlodelsheim : IDQuantitEnStockBlodelsheim = GetPropertyID("PD.QuantitEnStockBlodelsheim")
Dim valQuantitEnStockBlodelsheim : valQuantitEnStockBlodelsheim=PropertyValues.SearchForProperty(IDQuantitEnStockBlodelsheim).TypedValue.Value
if not isempty(valQuantitEnStockHeilligenberg) then tot = tot + valQuantitEnStockBlodelsheim

Dim IDQuantitEnStockHirtzfelden : IDQuantitEnStockHirtzfelden = GetPropertyID("PD.QuantitEnStockHirtzfelden")
Dim valQuantitEnStockHirtzfelden : valQuantitEnStockHirtzfelden=PropertyValues.SearchForProperty(IDQuantitEnStockHirtzfelden).TypedValue.Value
if not isempty(valQuantitEnStockHeilligenberg) then tot = tot + valQuantitEnStockHirtzfelden

output = tot

Function GetPropertyID(alias)
Dim iID
iID = Vault.PropertyDefOperations.GetPropertyDefIDByAlias(alias)
If iID = -1 Then
Err.Raise MFScriptCancel,"La propriété n'a pas été trouvée par l'alias"& alias
End If
GetPropertyID = iID
End Function

Parents
  • Hi I think you have a typo in your code all of your lines that are checking isEmpty are checking the same property's value

    "if not isempty(valQuantitEnStockHeilligenberg)".

    This means that if the "valQuantitEnStockHeilligenberg" is empty then non of the other fields will be added to the the Total sum. 

    if you update those to check that the correct property is empty it should work. 

    However if the isempty function is not working as expected you can also check if the value is not equal to an empty string ""

    for example:

    valQuantitEnStockHeilligenberg = PropertyValues.SearchForProperty(IDQuantitEnStockHeilligenberg).TypedValue.Value
    
    If valQuantitEnStockHeilligenberg <> "" Then
        tot = tot + valQuantitEnStockHeilligenberg
    End If 

Reply
  • Hi I think you have a typo in your code all of your lines that are checking isEmpty are checking the same property's value

    "if not isempty(valQuantitEnStockHeilligenberg)".

    This means that if the "valQuantitEnStockHeilligenberg" is empty then non of the other fields will be added to the the Total sum. 

    if you update those to check that the correct property is empty it should work. 

    However if the isempty function is not working as expected you can also check if the value is not equal to an empty string ""

    for example:

    valQuantitEnStockHeilligenberg = PropertyValues.SearchForProperty(IDQuantitEnStockHeilligenberg).TypedValue.Value
    
    If valQuantitEnStockHeilligenberg <> "" Then
        tot = tot + valQuantitEnStockHeilligenberg
    End If 

Children