Rev
This function returns an array containing copies of items from the input list, either in the normal order or in reverse order. The optional Count parameter defines how many items from the input list are included in the returned list.
Syntax
Rev(List [, Count [, Policy [, Seed]]])
Parameters
List
Type: None
Array, collection, or Categorical value to operate on.
Count
Type: Long
Optional. Number of items to return. If omitted, negative, or greater than the number of input items, all items are returned.
Policy
Type: Long
Optional. Controls the way the list order is chosen. See
Possible values for Policy below. The default is 1.
Seed
Type: Long
Optional. The state to be used for the reversal. The default is 0.
(return)
Type: None
An array consisting of a copy of the input list.
Remarks
An error occurs if List is a collection that doesn’t support the For Each...Next syntax. When List is a collection object, the return value is an array that contains copies of the objects in the collection and the input collection object is unchanged. Because the return value is an array, it does not have a Count property.
This function uses the reversal state stored by the mrScriptBasic engine or Evaluate component and passed as a hidden parameter. However, when both Policy and Seed are nonzero, the reversal state is set to Seed before the Policy is applied. If the resulting reversal state is even, the list is presented in normal order; if odd, the list is reversed.
The Rev function is similar to using the rev keyword in Quancept.
Possible values for Policy
0
No reversal and the reversal state is set to 0.
1
The reversal state is used without changing it.
2
The reversal state is incremented by one and used.
3
Use the starting point of the random number generator and update both the reversal state and the random number generator starting point.
Example
This example use Rev with museums (which is a multiple response variable in the UNICOM Intelligence Data File version of the Museum sample data set) in an SQL query. The example uses the Rev function four times, each time using a different value for the Policy parameter.
SELECT museums AS Museums,
Rev(museums, , 0) AS Policy0,
Rev(museums, , 1) AS Policy1,
Rev(museums, , 2) AS Policy2,
Rev(museums, , 3) AS Policy3
FROM vdata WHERE museums.AnswerCount() > 2
Here are the results for the first five respondents:
Museums Policy0 Policy1 Policy2 Policy3
------------- ------------ ------------- ------------- ------------
1 {25,28,29} {25,28,29} {25,28,29} {29,28,25} {25,28,29}
2 {26,28,29,30} {26,28,29,30} {26,28,29,30} {26,28,29,30} {26,28,29,30}
3 {25,26,27} {25,26,27} {25,26,27} {27,26,25} {27,26,25}
4 {25,28,30} {25,28,30} {25,28,30} {25,28,30} {30,28,25}
5 {25,26,27} {25,26,27} {25,26,27} {27,26,25} {25,26,27}
In column 1, Museums, the responses are presented as they are stored in the variable, which is the “normal” order. Notice that the responses are also presented in the normal order in the next two columns:
▪Column 2, Policy0, presents the responses in the normal order because Policy is set to 0 and Seed is not specified. This means that the list is presented in the normal order.
▪Column 3, Policy1, presents the responses in the normal order because Policy is set to 1 and Seed is not specified. This means that whether the list is reversed or not is determined by the current setting of the reversal state. However, because the Seed parameter has not been specified, the reversal state defaults to 0, which is an even number, and so the list is presented in the normal order. If we changed the query to specify the Seed parameter as 1, the order would be reversed, because 1 is an odd number.
Column 4, Policy2, shows the list in normal and reverse order alternately. This is because Policy is set to 2, which means that each time the function is called, one is added to the reversal state, thus causing it to alternate between odd and even values.
In the Policy3 column, the list is in normal and reverse orders at random because Policy is set to 3. This means that the reversal state is set to a random value each time the function is called. This means that the list is in normal and reverse order randomly.
See also