Page 1 sur 1

@Unique en LS

MessagePublié: 05 Jan 2005 à 16:26
par oguruma
j'ai récupéré le code sur breakingpar mais ce dernier ne fonctionnait pas à peu de choses près, j'ai donc fait les petites modif qui vont bien
voici le code corrigé
ça fonctionne super !

Code : Tout sélectionner

Function UniqueElements(PassedArray As Variant) As Variant
'// correction PassedArray fonctionne avec mieux avec un variant   
   Dim TempList List As Integer
   Dim NewArray As Variant
   Dim ArrayElement As String
   Dim i As Integer
   Dim Counter As Integer
   On Error Goto handleError
   For i = Lbound(PassedArray) To Ubound(PassedArray)
      ArrayElement = PassedArray(i)
'// correction d'une petite faute orthographe sur les variables
      TempList(ArrayElement) = 1
   Next   
   Counter = Lbound(PassedArray)   
'// correction ici, il manquait le redim initial
   Redim  NewArray(Counter)
   Forall IndEntry In TempList      
      Redim Preserve NewArray(Counter)      
      NewArray(Counter) = Listtag(IndEntry)
      Counter = Counter+1
   End Forall   
   UniqueElements = NewArray
   Exit Function
handleError:
   Msgbox "Erreur n° " & Err & " - " & Error$ & " - ligne " & Erl,16,"Error UniqueElements"
   Resume fin
fin:
End Function