ucArg

ucArgStr

 

See Also: ucDefineFunction, ucDefineOperator, ucArgCount, ucArgHandle, ucReturn

 

Retrieves the argument(s) or operand(s) of a callback routine.

 

ucArg(ExpressionHandle, ArgIndex)

- or -

ucArgStr(ExpressionHandle, ArgIndex)

 

Parameters

ExpressionHandle

All Native callback routines receive one argument, which is ExpressionHandle.  This handle is required as the first argument of ucArg().

 

ArgIndex

This represents the index of the argument you want.  If a callback routine definition has three parameters, and Expr is the expression handle, then ucArg(Expr, 1) retrieves the first argument, ucArg(Expr, 2) the second, and ucArg(Expr, 3) the third.  For an infix operator, ucArg(Expr, 1) is the left operand, and ucArg(Expr, 2) is the right operand.  For a unary operator, ucArg(Expr, 1) is the operand.

 

Remarks

·         Depending on the compiler, ucArg is mapped to double precision or extended precision.

 

 

.Example 1:  Using ucArg with a function definition

 

The following routine defines a function named Add, which returns the result of adding its two arguments.  So Add(5, 4) would return 9.  For more details on defining a function, see ucDefineFunction.

 

Visual Basic

' The line below can go in Form_Load()

ucDefineFunction "Native: Add(a, b)", AddressOf MyAdd

 

' The line below goes in a separate module

Sub MyAdd(ByVal Expr As Long)

   ucReturn Expr, ucArg(Expr, 1) + ucArg(Expr, 2)

End Sub

 

Examples for other compilers

 

 

Example 2:  Using ucArg with an operator definition

 

The following routine defines an operator named Plus, which returns the result of adding its two operands.  So 5 Plus 4 would return 9.  Note that the MyAdd callback is identical to the one in Example 1.  The only code that is different is the first line (ucDefineOperator ...).  The number 20 that comes after the word Native is the precedence level.  For more details on defining an operator, see ucDefineOperator.

 

Visual Basic

' The line below can go in Form_Load()

ucDefineOperator "Native: 20 {a} Plus {b}", AddressOf MyAdd

 

' The line below goes in a separate module

Sub MyAdd(ByVal Expr As Long)

   ucReturn Expr, ucArg(Expr, 1) + ucArg(Expr, 2)

End Sub

 

 

Example 3:  Using ucArgStr for a string argument

 

This example demonstrates the use of ucArgStr.  Myleft is a function that returns the left-most characters of a string, which is supplied as the first argument.  The second argument determines the number of characters to return.  It is based on VB's Left$() function.  For instance MyLeft("Hello World", 2) would return "He".

 

Visual Basic

' The line below can go in Form_Load()

ucDefineFunction "Native: MyLeft(Text As String, Count) As String", AddressOf MyLeft

 

' The line below goes in a separate module

Sub MyLeft(ByVal Expr As Long)

    ucReturnStr Expr, Left$(ucArgStr(Expr, 1), ucArg(Expr, 2))

End Sub

 

Additional examples can be found in the help topics for ucDefineFunction, and ucDefineOperator.

 

 

New or enhanced in version 3.0

·         Nothing related to this topic.

·         See What’s New.

 

Note: ucParam and ucParamStr were renamed ucArg and ucArgStr in version 3.0.  However, ucParam and ucParamStr are preserved for backward compatibility.

 

New or enhanced in version 2.96