Click or drag to resize

IMcOMGlobalMcOpSelect Method

Selected values from a Variant are returned.

Namespace:  MediaCy.IQL.ObjectManager
Assembly:  MediaCy.IQL.ObjectManager (in MediaCy.IQL.ObjectManager.dll) Version: 10.0.6912.0
Syntax
VB
Function McOpSelect ( 
	Operand As Object,
	<OptionalAttribute> varSelector0 As Object,
	<OptionalAttribute> varSelector1 As Object,
	<OptionalAttribute> varSelector2 As Object,
	<OptionalAttribute> varSelector3 As Object
) As McObject

Parameters

Operand
Type: SystemObject
Operand. May be a scalar or array of any numeric or string type.
varSelector0 (Optional)
Type: SystemObject
[in, optional] Optional selector for dimension 0 of vector data. Dim0 is the slowest moving dimension. If other selector arguments are missing and the number of dimensions in the selectors shape matches the number of dimensions in the Shape property, then selector values are treated as indices into the values unrolled into a 1-dimensional array.
varSelector1 (Optional)
Type: SystemObject
[in, optional] Optional selector for dimension 1 of vector data.
varSelector2 (Optional)
Type: SystemObject
[in, optional] Optional selector for dimension 2 of vector data.
varSelector3 (Optional)
Type: SystemObject
[in, optional] Optional selector for dimension 3 of vector data.

Return Value

Type: McObject
A McObject instance holding the selected elements of the Operand argument. The returned result will be of the type of Operand. It's shape will depend on which elements in which dimensions are selected.
Remarks
Up to 4 dimensions of optional index selectors may be supplied for vector data. If selectors are supplied, then the selected sub-array is returned as the value. The dimension selector may be a single, scalar index value or it may be an array of such values; negative indices in a selector are legal, but they are ignored. If the selector for a dimension is missing (VT_EMPTY, VT_ERROR or VT_NULL) then all elements of that dimension will be selected. For N-dimensional shaped McObject's, it is possible to supply selector values as indexes into the shape unwrapped into 1-dimensional array. This is done by supplying only the varSelector0 argument (leaving the other arguments missing) and supplying it as a N-dimensional array (if varSelector0 is supplied as a scalar or 1-D array, then it selects only from Dimension 0). The result of selecting in this way is a 1-dimensional array of the selected elements. This situation is actually a very common one, since the logical vector operators (e.g., McOMGlobal.McOpEq) preserve the shape of the left argument. The samples illustrate this and other selection rules: they are well worth examining if you are selecting from anything but 1-dimensional arrays. The selector arguments are supplied in C/C++ order for multidimensional shaped objects. That is, the left-most argument selects into Dim0, the slowest moving dimension. This is the same ordering as in C/C++, but it is the reverse of dimension ordering in VB. The returned subvector can differ subtly in its shape depending on whether a length-1 dimension selector is supplied as a length-1 array or as a scalar index value. If supplied as a scalar value, then the selected dimension is removed from the returned shape (the dimensionality drops by one), if supplied as an array, the dimension is kept and the returned value is always an array. A missing (e.g., VT_ERROR) selector on a variable inner dimension of a multidimensional object will always preserve the dimension and will always expose it as an array of VARIANT's if the mcobjUserFlagAlwaysVector UserFlags bit is set; if the mcobjUserFlagAlwaysVector UserFlags bit is clear then the dimension will be exposed as an array of VARIANT's only if the sizes of the elements of the dimension actually vary.
Examples
VB
'This module is SelectionSamples.bas
'It has VB samples for accessing selected subsets
'of the values in Variants and McObjects

Option Explicit

'***** Variant Examples *******
'The first set of examples uses native VB arrays (which are
'passed as Variants to methods).  Sucessive Sub's get more complex

Public Sub SelectFrom1DVariant()
    Output.Show "Output"
    Output.Clear
    Dim var1D As Variant
    var1D = Array(1, 2, 3, 4, 5)
    Output.PrintMessage "Select Elements 0,4,2 from (1,2,3,4,5) in that order: " & _
        McToText(McOpSelect(var1D, Array(0, 4, 2))) 'show 1 5 3
End Sub 'SelectFrom1DVariant

Public Sub AssignToSelectedValuesOf1DVariant()
    Output.Show "Output"
    Dim array1D(3) As Long 'length-4 array
    Dim varT As Variant
    varT = array1D
    McOpAssignSelected varT, Array(1, 2), Array(0, 2)
    Output.PrintMessage "Assigned-to array. " + McToText(varT) 'show 1 0 2 0
End Sub 'AssignToSelectedValuesOf1DVariant

Public Sub SelectValuesGreaterThan10()
    Output.Show "Output"
    Dim var1D As Variant
    var1D = Array(1, 20, 3, 40, 5, 60)
    Output.PrintMessage "Select values from (1,20,3,40,5,60) greater than ten: " + _
        McToText(McOpSelect(var1D, McOpGT(var1D, 10))) 'show 20 40 60
End Sub 'SelectValuesGreaterThan10

Public Sub SelectFrom2DVariant()
    Output.Show "Output"
    Output.Clear
    Dim var2D As Variant
    var2D = Array(Array(11, 21, 31, 41), Array(12, 22, 32, 42), Array(13, 23, 33, 43))
    Output.PrintMessage "Original 2-D array:" + vbCrlf + McToText(var2D)
    Output.PrintMessage "Select 3rd Row: " & _
        McToText(McOpSelect(var2D, 2)) 'show 13 23 33 43
    Output.PrintMessage "Select 2nd Column: " & _
        McToText(McOpSelect(var2D, Empty, 1)) 'show 21 22 23
    Output.PrintMessage "Select 2nd and 4th Column from 1st Row: " & _
        McToText(McOpSelect(var2D, 0, Array(1, 3))) 'show 21 41
    Output.PrintMessage "Select 2nd and 4th Columns: " & vbCrlf & _
        McToText(McOpSelect(var2D, Empty, Array(1, 3))) 'show 21 41, 22 42, 23 43
    Output.PrintMessage "Select 4th, 2nd and 1st Column from 1st and 3rd Row: " & vbCrlf & _
        McToText(McOpSelect(var2D, Array(0, 2), Array(3, 1, 0))) 'show 41 21 11, 43 23 13
    Output.PrintMessage "Select values Greater than 32: " & vbCrlf & _
        McToText(McOpSelect(var2D, McOpGT(var2D, 32))) 'show 41 42 33 43
    'The McOpGT selector in the above statement is a 2-D array that
    'selects from both rows and columns, the resulting McOpSelect is a 1-D array.
End Sub 'SelectFrom2DVariant

Public Sub AssignToSelectedValuesOf2DVariant()
    Output.Show "Output"
    Output.Clear
    Dim var2D As Variant
    var2D = Array(Array(11, 21, 31, 41), Array(12, 22, 32, 42), Array(13, 23, 33, 43))
    Output.PrintMessage "Original 2-D array:" + vbCrlf + McToText(var2D)
        'Assign 2, 3, 4 to the 1st column
    McOpAssignSelected var2D, Array(2, 3, 4), Empty, 0
    Output.PrintMessage "** 2,3,4 assigned to 1st column: " & vbCrlf & _
        McToText(var2D)  'show 2 21 31 41, 3 22 32 42, 4 23 33 43
        'Zero all odd values in the above
    McOpAssignSelected var2D, 0, McOpNE(McOpAndBits(var2D, 1), 0)
    'The McOpNE selector in the above statement is a 2-D array that
    'selects elements in both rows and columns for assigment.  Note also
    'how the associative assignment used the RightOperand scalar value of zero
    'repeatedly as necessary to assign to all selected (odd) values.
    Output.PrintMessage "** All odd values of above array zero'ed: " & vbCrlf & _
        McToText(var2D)  'show 2 0 0 0, 0 22 32 42, 4 0 0 0
End Sub 'AssignToSelectedValuesOf2DVariant

'***** McObject Examples *******
'The next set of examples uses McObjects to hold arrays of data.
'The first 5 Sub's are versions of the above that use a McObject to
'hold the array data instead of a Variant.
'Sucessive Sub's get more complex

Public Sub SelectFrom1DMcObject()
    Output.Show "Output"
    Output.Clear
    Dim mcobj1D As McObject
    Set mcobj1D = McObjectTemp(Array(1, 2, 3, 4, 5))
    Output.PrintMessage "Select McObject elements 0,4,2 from (1,2,3,4,5) in that order: " & _
        McToText(mcobj1D.SelectedMcObject(Array(0, 4, 2)))  'show 1 5 3
    Output.PrintMessage "This does the same thing (with an extra internal copy): " & _
        McToText(McOpSelect(mcobj1D, Array(0, 4, 2)))  'show 1 5 3
End Sub 'SelectFrom1DMcObject

Public Sub AssignToSelectedValuesOf1DMcObject()
    Output.Show "Output"
    Dim mcobjT As McObject
    Set mcobjT = McArrayTemp("INTEGER", 4) 'length-4 1-D array
    mcobjT.SelectedValues(Array(0, 2)) = Array(1, 2)
    Output.PrintMessage "Assigned-to McObject array. " + McToText(mcobjT) 'show 1 0 2 0
End Sub 'AssignToSelectedValuesOf1DMcObject

Public Sub SelectValuesGreaterThan10FromMcObject()
    Output.Show "Output"
    Dim mcobj1D As McObject
    Set mcobj1D = McObjectTemp(Array(1, 20, 3, 40, 5, 60))
    Output.PrintMessage "Select McObject values from (1,20,3,40,5,60) greater than ten: " + _
        McToText(mcobj1D.SelectedMcObject(McOpGT(mcobj1D, 10)))  'show 20 40 60
    Output.PrintMessage "This does the same thing (with an extra internal copy): " + _
        McToText(mcobj1D.SelectedValues(McOpGT(mcobj1D, 10)))  'show 20 40 60
    Output.PrintMessage "This also does the same thing with an extra copy: " + _
        McToText(McOpSelect(mcobj1D, McOpGT(mcobj1D, 10))) 'show 20 40 60
End Sub 'SelectValuesGreaterThan10FromMcObject

Public Sub SelectFrom2DMcObject()
    Output.Show "Output"
    Output.Clear
    Dim mcobj2D As McObject
    Set mcobj2D = McArrayTemp("INTEGER", Array(3, 4)) '3 rows by 4 columns
    mcobj2D.OpSelfAssign (Array(Array(11, 21, 31, 41), Array(12, 22, 32, 42), Array(13, 23, 33, 43)))
    Output.PrintMessage "Original 2-D array:" + vbCrlf + McToText(mcobj2D)
    Output.PrintMessage "Select McObject 3rd Row: " & _
        McToText(mcobj2D.SelectedMcObject(2))  'show 13 23 33 43
    Output.PrintMessage "Select 2nd Column: " & _
        McToText(mcobj2D.SelectedMcObject(Empty, 1)) 'show 21 22 23
    Output.PrintMessage "Select 2nd and 4th Column from 1st Row: " & _
        McToText(mcobj2D.SelectedMcObject(0, Array(1, 3))) 'show 21 41
    Output.PrintMessage "Select 2nd and 4th Columns: " & vbCrlf & _
        McToText(mcobj2D.SelectedMcObject(Empty, Array(1, 3))) 'show 21 41, 22 42, 23 43
    Output.PrintMessage "Select 4th, 2nd and 1st Column from 1st and 3rd Row: " & vbCrlf & _
        McToText(mcobj2D.SelectedMcObject(Array(0, 2), Array(3, 1, 0))) 'show 41 21 11, 43 23 13
    Output.PrintMessage "Select McObject values Greater than 32: " & vbCrlf & _
        McToText(mcobj2D.SelectedMcObject(McOpGT(mcobj2D, 32))) 'show 41 42 33 43
    'The McOpGT selector in the above statement is a 2-D array that
    'selects from both rows and columns, the resulting SelectedMcObject property is a 1-D array.
    Output.PrintMessage "This does the same thing (with an extra internal copy): " & vbCrlf & _
        McToText(McOpSelect(mcobj2D, McOpGT(mcobj2D, 32)))   'show 41 42 33 43
End Sub 'SelectFrom2DMcObject

Public Sub AssignToSelectedValuesOf2DMcObject()
    Output.Show "Output"
    Output.Clear
    Dim mcobj2D As McObject
    Set mcobj2D = McObjectTemp(Array(Array(11, 21, 31, 41), Array(12, 22, 32, 42), Array(13, 23, 33, 43)))
        'Compare the above to the way mcobj2D was filled in SelectFrom2DMcObject, above.
        'The results are equivalent except that this McObject will have type "SHORT" (16-bit
        'integer), since that is the VB integer type of the Array statements here.  The
        'McArrayTemp then OpSelfAssign gives you more control (e.g., you could fill all
        'rows the same without having to specify them all).
    Output.PrintMessage "Original 2-D array:" + vbCrlf + McToText(mcobj2D)
        'Assign 2, 3, 4 to the 1st column
    mcobj2D.SelectedMcObject(Empty, 0) = Array(2, 3, 4)
    'the following would work too
    'McOpAssignSelected mcobj2D, Array(2, 3, 4), Empty, 0
    Output.PrintMessage "** 2,3,4 assigned to 1st column: " & vbCrlf & _
        McToText(mcobj2D)  'show 2 21 31 41, 3 22 32 42, 4 23 33 43
        'Zero all odd values in the above
    mcobj2D.SelectedMcObject(McOpNE(McOpAndBits(mcobj2D, 1), 0)) = 0
    'The McOpNE selector in the above statement is a 2-D array that
    'selects elements in both rows and columns for assigment.  Note also
    'how the associative assignment used the assigning scalar value of zero
    'repeatedly as necessary to assign to all selected (odd) values.
    Output.PrintMessage "** All odd values zero'ed: " & vbCrlf & _
        McToText(mcobj2D)  'show 2 0 0 0, 0 22 32 42, 4 0 0 0
End Sub 'AssignToSelectedValuesOf2DMcObject
See Also