Danaher Motion
06/2005
GENERIC ELEMENTS
M-SS-005-03 Rev
E
147
Generic elements can also serve as returned values of MC-Basic functions.
Both “real” and generic elements can be assigned to returned values. For
example, to generalize the former code, an axis-indexing function can be
added, in which a “real” axis is assigned to the return value:
Function JointAxisByIndex(Byval I As Long) As Generic Axis
Select Case I
Case 1
JointAxisByIndex = G1.J1
Case 2
JointAxisByIndex = G1.J2
…
End Select
End Function
Then, write a general loop:
Dim A As Generic Axis
For Index = 1 to Sys.NumberAxes
A = AxisByIndex(Index)
Call AxisSetUp(A)
Next
The generic element-returning function itself cannot be used as an argument
since generic elements can only be passed by reference,and a function call
is passed by value.
For Index = 1 to Sys.NumberAxes
Call AxisSetUp( AxisByIndex(Index) )
Next
-> Cannot pass a constant or a complex expression by reference to
subroutine/function
Joint (J) axes cannot be assigned to return values.
Function JointAxisByIndex(Byval I As Long) As Generic Axis
Select Case I
Case 1
JointAxisByIndex = G1.J1
Æ
Syntax Error
Case 2
JointAxisByIndex = G1.J2
Æ
Syntax Error
…
End Select
End Function