Autor Tema: Funcion para buscar duplicados en array  (Leído 3580 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Bazooka

  • Terabyte
  • *****
  • Mensajes: 951
  • Reputación: +31/-20
  • El pibe Bazooka
    • Ver Perfil
    • Desof sistemas
Funcion para buscar duplicados en array
« en: Agosto 03, 2011, 08:48:12 am »
Hola Alguien tiene una función para buscar duplicados en un arrary o matriz como este:


1,5,7,12,33,45,56,65,77,89,90
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

Bazooka

  • Terabyte
  • *****
  • Mensajes: 951
  • Reputación: +31/-20
  • El pibe Bazooka
    • Ver Perfil
    • Desof sistemas
Re:Funcion para buscar duplicados en array
« Respuesta #1 en: Agosto 03, 2011, 09:08:19 am »
Me respondo sólo!!!! encontre la solucion y por ahi le sireve a alguien:



Código: [Seleccionar]
Private Sub Command1_Click()
   Dim mat() As String
   Dim t
   
t = "1,2,3,4,5,6,7,8,9,11,13,14,15,16,55"

mat() = Split(t, ",")
If HayDuplicados(mat()) Then MsgBox "Hay Dubplicados"
End Sub


Private Function HayDuplicados(sElementos() As String) As Boolean
    Dim TempArray() As String
    Dim x As Integer, x2 As Integer, y As Integer
    Dim z As Integer, Elemento As Variant
    Dim ArrFinal() As Variant
    Dim nRedim As Long
   
    Dim i As Integer
    For i = LBound(sElementos) To UBound(sElementos)
       ReDim Preserve TempArray(i)
       TempArray(i) = sElementos(i)
    Next
    For x = 0 To UBound(sElementos)
        z = 0
        For y = 0 To UBound(sElementos)
            If sElementos(x) = TempArray(z) And y <> x Then
                sElementos(y) = ""
                nRedim = nRedim + 1
                HayDuplicados = True
                Exit Function
            End If
            z = z + 1
        Next y
    Next x
     
End Function
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.