我有一数组,w(2,2,3,3,3,4,6,6,7,9)
我现只想取其没有重复的,即:w(2,3,4,6,7,9)
并按从小到大排序,ok
请那位高手给于指点.......

解决方案 »

  1.   

    '假设你的数组有n 个元素,下面程序只是删除重复元素   dim i,j,k as integer
       dim work(n) as integer
       for i=0 to n
         for j=i+1 to n
             if w(i) <> w(j) then 
                w(k)=w(j)
                 k=k+1
             else
                w(k)=w(j)
             end if
        loop j
      loop i
      

  2.   


    Private Sub Command1_Click()    Dim strA() As String
        Dim strB() As String
        Dim strTemp As String
        Dim i, j, k As Integer
        
        strA() = Split("7,2,9,3,5,4,2,6,3,9", ",")
    '    ReDim strB(LBound(strA()) To UBound(strA()))
        For i = LBound(strA()) To UBound(strA())
            ' del the same
            If strA(i) <> "" Then
                For j = i + 1 To UBound(strA())
                    If strA(j) <> "" Then
                        If strA(i) = strA(j) Then
                            strA(j) = ""
                            k = k + 1
                        End If
                    End If
                Next j
            End If
        Next i
        
        For i = LBound(strA()) To UBound(strA()) - 1
            ' reorder
            For j = LBound(strA()) To UBound(strA()) - 1
                If Val(strA(j)) > Val(strA(j + 1)) Then
                    strTemp = strA(j + 1)
                    strA(j + 1) = strA(j)
                    strA(j) = strTemp
                End If
            Next j
        Next i
        
        strTemp = ""
        
        For i = LBound(strA()) To UBound(strA())
            If strA(i) <> "" Then
                strTemp = strTemp & strA(i) & ","
            End If
        Next i
        strTemp = Left(strTemp, Len(strTemp) - 1)
        MsgBox strTempEnd Sub
    写的比较麻烦,希望能看到更好的代码。