Once the script space area has been created as shown in Creating Custom Scripts that space is where the method needed from a special function can be scripted.  A user's Custom Function can be complex or as simple as adding to numbers of changing the case of a text value.


Values to be used in a user function are sent to the user function by adding parameters to the calling statement of the user function:


Let's assume we wanted to add two numbers together.  We first need to give the function a name.  In this example we'll call the function "AddTwoNumbers" which will also be the Custom Function Script Section name.


To execute that function we need to call that function from another script.  Any other script can call any other script section.  This also included any of the Trading Blox standard script sections.  


For our example we need to pass our function two values.  How we get those values is not important, but they must be valid within the script area from which we call this custom function:

'  Assign a value to each of the two Floating Point BPV values:
AnyRandom1 = Random( 1, 100 )
AnyRandom2 = Random( 1, 100 )

Calling "AddTwoNumbers" needs a statement that will access the created custom script section and pass that section the value of two number:

'  This statement will work
script.execute("AddTwoNumbers", AnyRandom1, AnyRandom2)

Within our custom script section we will use two script properties to access the passed value so we can add them together:

'  Create two local floating point values
VARIABLES: anyValue1, anyValue2, sumValue TYPE: Floating
'  Access the values in each of the numeric
'  parameters passed to this function
anyValue1 = script.parameterList[1]
anyValue2 = script.parameterList[2]
'  Add the numbers together
sumValue = anyValue1 + anyValue2
'  Return the sum of the two values
'  to the calling script section
script.SetReturnValue( sumValue )

If the value of the returned numbers were 1 and 2 the return value will equal 3.


Access to a single return value, multiple values can be returned, is available in three ways:

'  To directly return the results of a called script

'  let the calling statement assign its return value
addedValue = script.execute("AddTwoNumbers", AnyRandom1, AnyRandom2)
'  To access the value returned using a property, place
'  the property assignment after the calling statement
addedValue = script.returnValue
'  To send the returned value to the Print Output.csv file
'  call the custom script statement using the PRINT function.
PRINT script.execute("AddTwoNumbers", AnyRandom1, AnyRandom2)


If more examples are needed, use the Help file's email option or use the static Help file topic in the forum.


Created with Help & Manual 7 and styled with Premium Pack Version 2.80 © by EC Software