Home Search

DriveWorks Pro 23
DWLambda

Send Feedback

DWLambda

DWLambda allows custom, reusable functions to be created.

DWLambda effectively adds your own functions to a DriveWorks Project and can be used to:

  • create commonly used formula
  • eliminate the need to recreate the same formula in many places
  • create complex formula
  • embed existing functions within the formula

DWLambda is added to a Project by:

  1. Creating the DWLambda, typically as a Variable.
  2. Consuming the Variable as a new, custom function.

    The new function passes values into the parameters declared in the DWLambda.

Testing a DWLambda

The DWLambda can be tested before it is consumed in a variable.

See Passing Values Directly into the DWLambda Parameters for more information.

Syntax

DWLambda([Collection of Parameters], [Function])

Where:

Parameters are the names of Lambda References to be used within the Lambda Function. Each parameter is separated with a comma (,), for example a,b,c.

Function is the Lambda function to be executed. The function references each named parameter, for example a*b/c.

Examples

Convert inches to millimeters

Create the Variable ConvertInchToMM and apply the following DWLambda function:

DWLambda(inch, 
         inch * 25.4
         )

Next use the Variable anywhere the conversion is required, as follows:

DWVariableConvertInchToMM(5)

will return 127 (5*25.4).

Or

DWVariableConvertInchToMM(TextBox1Return)

will return 50.8 if the TextBox1 control equals 2 (2*25.4).

Volume (of a cube)

Create the Variable Volume and apply the following DWLambda function:

DWLambda(height, width, depth,
         height * width * depth
         )

Next use the Variable anywhere the conversion is required, as follows:

DWVariableVolume(3, 5, 2)

will return 30 (3*5*2).

Or

DWVariableVolume(HeightReturn, WidthReturn, LengthReturn)

will return 30 when the controls equal 3, 5 and 2 (3*5*2).

Hole Pitch

Create the Variable HolePitch and apply the following DWLambda function:

DWLambda(Length, FirstHole, LastHole, HoleQty,
        (Length-FirstHole-LastHole)/(HoleQty-1)
        )

Next use the Variable anywhere the HolePitch is required, as follows:

DWVariableHolePitch(LengthReturn, 50, 75, 11)

will return 287.5 when the control equals 3000 ((3000-50-75) / (11-1)).

Volume (of a cylinder)

This example demonstrates using a variable that calculates the height (DWVariableCylinderHeight) and the DriveWorks Functions Pi and Power within a DWLambda.

Create the Variable VolumeCyl and apply the following DWLambda function:

DWLambda(radius,
         PI() * Power(radius,2) * DWVariableCylinderHeight
         )

Next use the Variable anywhere the conversion is required, as follows:

DWVariableVolumeCyl(20)

will return 376991.1 = Pi * 20 2 * 300 (the result of DWVariableCylinderHeight).

Passing Values Directly into the DWLambda Parameters

A useful feature of the DWLambda is the ability to pass values into the function without requiring to create a consuming variable.

This aids testing and validating the DWLambda function created as the result can be seen directly in the Rules Builder.

To do this include the required values enclosed within parenthesis after the DwLambda() function.

For example:

DWLambda(inch, inch * 25.4)(10)

Will pass the value 10 into the expected inch parameter and return the result 254 directly in the rule builder.

Or

DWLambda(Length, FirstHole, LastHole, HoleQty, (Length-FirstHole-LastHole)/(HoleQty-1))(3000,50,75,11)

Will pass the values 3000,50,75,11 into the expected parameters (Length, FirstHole, LastHole and HoleQty) and return the result 287.5 directly in the rule builder.

This is intended to allow the DWLambda to be tested while constructing the function.

Please remember to remove the added values to allow the function to equate as expected when being consumed in a variable.

Restrictions

The following restrictions have been intentionally implemented to prevent ambiguity between which slot, of the function, is being referenced (either where the Lambda Function is defined or where it is called).

MyName and MyNumber functions are blocked when being called from within a DWLambda function.

Relative cell references (for example in a Calculation Table the reference [1L]) are blocked when being called from within a DWLambda function.

A relative reference or the MyName function can be passed into the DWLambda, as an argument, from outside the DWLambda function call.