Navigation:  MCL Reference > List Functions >

ListAscItem( )

Print this Topic Previous pageReturn to chapter overviewNext page

The function sorts an item string in ascending order and returns a specific item. If the items of the item string contain sub-items, you may specify a sub-item as the sorting key. The function can return an item, a sub-item, or the ordinal of an item.

 

Syntax

ListAscItem(cValueExpr,nItemNumber,cSeparator,nSortSubItem,cSubItemSeparator,cReturnType)

Or

ListAscItem(cValueExpr,nItemNumber,cSeparator,cSortExpr,cSubItemSeparator,cReturnType)

 

Argument

Description

Example

cValuleExpr

The item string or an expression returning an item string

'12:45/6:00/9:40'

nItemNumber

An ordinal number specifying which item, after sorting, to be returned

3

cSeparator

Item separator, can be more than 1 character (default to ',')

'/'

nSortSubItem

An ordinal number specifying which sub-item to be sorted. If omitted, the whole item will be sorted

2

cSortExpr

Use the value returned by ListCol( ) and ListColVal( ) to determine the order. Please see the examples below for details

'ListColVal(1)+ListColVal(2)

cSubItemSeparator

Sub-item separator, can be more than 1 character (default to '-')

':'

cReturnType

'I': Returns the ordinal number, before sorting, of the item.

'R': Returns the whole item

Omitted or any other character: returns the sub-item

'I'

 

Returns

Character

 

Example

ListAscItem('Orange,Apple,Grape,Pear',2)

Returns 'Grape'. After sorting, the item string becomes: 'Apple,Grape,Orange,Pear',The 2nd item is 'Grape'.

 

ListAscItem('12:45/6:00/9:40',3,'/',2,':','I')

Returns 1. The 2nd sub-items of the item string are '45', '00', and '40' respectively. After sorting on the 2nd sub-items, the item string becomes '6:00/9:40/12:45', the 3rd item is  '12:45', the ordinal number of this item before sorting is 1 (cReturnType='I').

 

ListAscItem('5-4,23-15,3-26',1,,2)

Returns  '15'. The 2nd sub-items of the item string are  '4', '15' and '26' respectively. (Please note that when comparing strings, '4' is greater than '15' since '4' > '1'. When comparing numbers, 4 is smaller 15) Therefore, after sorting, the item string becomes  '23-15,5-4,3-26' and the function returns the sub-item '15' of the first item (sub-item is returned if argument cReturnType is omitted).

 

ListAscItem('5-4,23-15,3-26',1,,2,,'R')

Returns  '23-15'. This example is similar to the example above. The only difference is the whole item is returned (cReturnType='R') instead of the index index.

 

In the example view in the figure below, the column "WeightFp" returns an item string of both the weight and the finishing position of 8 past starts of each horse by scanning the history only once. Columns "Lightest" and "Best" utilize the ListAscItem( ) function to sort the list by weight and finishing position respectively and returns the minimum values of the data. Instead of doing it this way, you may apply the functions HrMinimum('HrWeight( )',8) and HrMinimum('HrFP( )',8) to get the same results. However, each of these functions scans the history once. Thus the history will be scanned twice. The speed is slower than that of the view in this example.

 

Column

Formula

Data Type

Horse

(Built-in column)

 

WeightFp

HrHistoryList("Str(HrWeight( ),3)+'-'+Str(HrFP( ),2)",8)

Text (56)

Lightest

ListAscItem(Column(' WeightFp '),1,,1)

Text (3)

Best

ListAscItem(Column(' WeightFp '),1,,2)

Text (2)

 

 

ListAscItem('5-4,6-1,2-6',1,,'ListColVal(1)+ListColVal(2)')

Returns  '6-1'. The argument 'ListColVal(1)+ListColVal(2)' asks the system to sort on the numeric sum of the 1st and 2nd sub-items:

Item

ListColVal(1)+ListColVal(2)

'5-4'

5 + 4 = 9

'6-1'

6 + 1 = 7

'2-6'

2 + 6 = 8

Since 7<8<9, after sorting the item string becomes '6-1,2-6,5-4'. The function returns the first item '6-1'.

 

ListAscItem('5-4,6-12,2-6',1,,'ListCol(1)+ListCol(2)')

Returns '6-1'. The argument 'ListCol(1)+ListCol(2)' ask the system to sort on the concatenation of the 1st and the 2nd sub-items:

Item

ListCol(2)+ListCol(1)

'5-4'

'4' + '5' = '44'

'6-12'

'12' + '6' = '126'

'2-6'

'6' + '2' = '62'

Since '126'<'44'<'62' (note: '126'<'44' because '1'<'4'), the item string after sorting becomes '6-12,5-4,2-6'. The function returns the first item '6-12'.

 

See also

ListDescVal( ) | ListDescVal( ) | ListAscVal( ) | ListItem( ) | ListVal( ) | ListSum( ) | ListAverage( ) | ListFilter( ) |

 

 


Page url: http://www.racematenet.com/english/help/index.html?listascitem.htm