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

Use VB-Script to do calculations

Hi,

I saw that there is an option to use VB-Script to do calculations.

Example:

Property A =100

Property B = property A * 1.17

So with VB-Script I can calculate this.

Questions:

1. How can I reference the VB-Script to "use" property A?

I think that I saw that there is an option with alias or ID

2. If I have property "Client" and property A is in his metadate, How can I reference the VB-Script to "use" property A?

3. Do you have examples of using calculations VB-Script in M-Files?

4. For using calculations I need to use specific type to the properties?

Parents
  • Hi Idan,

    1. Below is a sample script for calculating VAT. It should help you get started.
    2. In that situation you would first have to get the propertyvalues from the client and then get property A from those propertyvalues.
    3. Se sample below
    4. The type needs to be able to hold the output data. If the result has decimal values you cannot use an integer type property. But you can use Number (Real) or Text

    'Script for calculating invoice amount + VAT, automatic value
    Option Explicit
    Dim iPDAmount : iPDAmount = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("PD.Amount")
    Dim iVAT : iVAT = 25 'percentage of VAT
    Dim szAmount : szAmount = PropertyValues.SearchForProperty(iPDAmount).TypedValue.DisplayValue
    'err.raise mfscriptcancel, szAmount & "  " & szAmount * ("1," & iVAT)
    if not szAmount = "" then
    	Output = szAmount * ("1," & iVAT)
    end if

Reply
  • Hi Idan,

    1. Below is a sample script for calculating VAT. It should help you get started.
    2. In that situation you would first have to get the propertyvalues from the client and then get property A from those propertyvalues.
    3. Se sample below
    4. The type needs to be able to hold the output data. If the result has decimal values you cannot use an integer type property. But you can use Number (Real) or Text

    'Script for calculating invoice amount + VAT, automatic value
    Option Explicit
    Dim iPDAmount : iPDAmount = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("PD.Amount")
    Dim iVAT : iVAT = 25 'percentage of VAT
    Dim szAmount : szAmount = PropertyValues.SearchForProperty(iPDAmount).TypedValue.DisplayValue
    'err.raise mfscriptcancel, szAmount & "  " & szAmount * ("1," & iVAT)
    if not szAmount = "" then
    	Output = szAmount * ("1," & iVAT)
    end if

Children