ISIntCollection.AddSortedDistinct

Description

This function adds the distinct integer values to the collection and sorts them.

Syntax

object.AddSortedDistinct(aValue)

Part Attribute Type Description
object Required
The object always implements the ISIntCollection interface
aValue In, Required
int
The integer value

Return Value

bool

Returns True if the distinct integer values were successfully added and sorted within the collection.

Example

Fill in the collection with randomized integer values, display their count and indices within the collection.

Dim aItemCount
Dim aIntColl
Dim aValue
Dim aResultCount
Dim aUsedIndices
Dim aIndex
Dim aMessage

aItemCount = 70

Set aIntColl = Profile.CreateIntCollection

for i = 1 to aItemCount
  aValue = i * 10
  aIntColl.Add(aValue)
next

Randomize

aResultCount = 10
set aUsedIndices = Profile.CreateIntCollection

do
  aIndex = Int(aItemCount * Rnd)
  aUsedIndices.AddSortedDistinct(aIndex) 
loop until aUsedIndices.Count = aResultCount   

for i = 0 to aUsedIndices.Count - 1
  aIndex = aUsedIndices.Item(i)
  aValue = aIntColl.Item(aIndex) 

  aMessage = aMessage & vbNewLine & "IntValue(" & aIndex & ") = " & aValue  
next 

Profile.MsgBox(aMessage)
Note:

Version information

Added in v8.5.0