Word+equate allows the user to create VB.Net style functions which can greatly improve the capabilities of your document. Users can save and share created functions with other users.

 Functions are created by selecting the ‘Insert Function’ command under the Calculations Tab.

This displays a dialog in which to define the function.


In order to create a function there are 5 key elements which must be included, in order to successful compile:

  1. Function Name: the name which when typed in the equation editor will execute the script, therefore it must be unique and briefly describe the function.
  2. Input Variables: These are the variable which you want to use in the function, note: you can pass any of the available variables into a function (Number, Quantity, Array, Matrix, Boolean and Text) but each one contains a slightly different set of possible operations.
  3. Body: contains the operations in the program.
  4. Return: The result of the function which you want to send back to the word document
  5. End function: in order to complete the function you must finish with End Function

On completion, click Compile. This compiles the code. If errors are found, these must be fixed before proceeding. 

Example 1

This example simply adds two variables.  

Add(a, b)
    Dim result as variable = a+b
    return result
end function

Add is the name of the function. "a" and "b" are the passed arguments. 

The variable "result" is created and given the value of the sum of "a" and "b".

The value of the variable "result" is returned.

User functions implement unit and variable type behavior with any additional code required. The examples below show various implementations of the function. 

Note that the returned result has a type of “variable”. This is a generic type that may include values (simple unitless numbers) or quantities (values with or without a unit). The “+” operator will act on the variables “a” and “b” based on their type. If values, they will be simply added. If “a” and “b” are vectors, then the vector addition will result in a new vector. 

Example 2

This function ensures that a value is in the range of 0.67 to 0.85.

Since the “<” and “>” operators require the same variable type for both compared variables, the “a” must be a value (i.e be unitless).


    Dim result as Variable
    If a > 0.85 then
       result = 0.85
    else if a < 0.67 then
       result = 0.67
       result = a
    end if
    return result
end function

The following equations can then be used within the body of the document.


Technical Stuff

The Word+Equate compiler fully compiles the function code to a locally stored, .net dynamic linked library (dll). The dll file is automatically registered.

As such, performance for complex or repetitive calculations is very good.

Generally all Word+Equate documents show complete calculations, so a reviewer of the printed document can verify every step. User functions allow the creation of "black box" components. The code of the user function is invisible in the printed document. User functions can therefore be used to conceal proprietary methods. They can also be used to implement iterative procedures, where only the final result need be documented.

Within the vb.net environment it is relatively simple to access an existing registered class. For example, it is possible to create a user defined function to use a MS-Excel object to access data or calculations in a spreadsheet. It is similarly possible to fetch data from a web site.

For further information of programming in vb.net(R), refer to the Microsoft(R) website.

The source code of any defined functions is stored in the weq version of the saved data.