Home Search

DriveWorks Pro 22
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.

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).

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.