quinta-feira, 5 de agosto de 2010

Equivalente @Unique

Function Unique(sourceList As Variant) As Variant
On Error Goto errorHandle
Dim uniqueList List As Variant
Dim returnArray() As Variant ' return value
Dim count%

' Check to see we have more than one value
If Isscalar( sourceList ) Then
Unique = sourceList

Else
' Unique the values
Forall v In sourceList
uniqueList( Cstr( v ) ) = v

End Forall 'v in sourceList

Redim returnArray( 0 To Elements( uniqueList ) -1 )
' Set the
return array to be zero based

'Turn the values into an array
count% = 0
Forall u In uniqueList
returnArray( count% ) = u
count% = count% + 1

End Forall 'u In uniqueList

Unique = returnArray

End If 'isscalar


Exit Function
errorHandle:
Error Err, "[TextLib] [Unique] (" & Cstr(
Erl ) & ")" & Chr$(13) & Error$
Exit Function

End Function

Nenhum comentário:

Postar um comentário