现有一文本文件,里面有一些数据,如何按从小到大的顺序排列?比如:文本中有五条数据,
021025560278223
021025560268342
021024620943221
345675390223452
345673782649576
前五位数据不管,对从第6位的数据开始进行比较大小,按从小到大的顺序排!排列后的结果为:
345673782649576
021024620943221
345675390223452
021025560268342
021025560278223
请哪位知道的朋友指点一下,能给个代码最好!谢谢了~~~

解决方案 »

  1.   


        Dim txt(), i As Long
        txt = Array("021025560278223", "021025560268342", "021024620943221", "345675390223452", "345673782649576")
        
        For i = LBound(txt) To UBound(txt)
            txt(i) = Left(txt(i), 5) & Mid(txt(i), 6)
        Next
        
        '对数组进行排序,代码略...
        
        For i = LBound(txt) To UBound(txt)
            txt(i) = Right(txt(i), 5) & Mid(txt(i), 1, Len(txt(i)) - 6)
        Next
      

  2.   

    用两个listbox,list1的sorted属性为true,list2的sorted属性为false,把数据放入list1中排完序后再挪到list2中,很笨的一个方法了:
    Private Sub Command1_Click()
        List1.Clear
        List2.Clear
        Dim s As String, i As Integer
        Open "c:\input.dat" For Input As #1
        For i = 1 To 32767
            If EOF(1) Then
                Close #1
                Exit For
            Else
                Line Input #1, s
                List1.AddItem Right(s, Len(s) - 5) & Left(s, 5)
            End If
        Next
        For i = 0 To List1.ListCount - 1
            List2.AddItem Right(List1.List(i), 5) & Mid(List1.List(i), 1, Len(List1.List(i)) - 5)
        Next
    End Sub
      

  3.   

    因为排序后还要对数据进行处理、分类,然后再生成新的TXT文本,这样最后生成的文本中数据就是按顺序排好的了
      

  4.   

    Private Function Sort(ByRef mSort() As String) As String
        Dim Temp As Double
        Dim i As Integer, j As Integer
        For i = 0 To UBound(mSort)
            For j = i + 1 To UBound(mSort)
                If CDbl(mSort(i)) > CDbl(mSort(j)) Then
                    Temp = mSort(i)
                    mSort(i) = mSort(j)
                    mSort(j) = Temp
                End If
            Next
            Sort = Sort + "," + mSort(i)
        Next
        Sort = Mid(Sort, 2)
    End FunctionPrivate Sub Command1_Click()    Dim txt() As Variant
        Dim txt_sort() As String
        Dim i As Long
        Dim c As New Collection
        
        txt = Array("021025560278223", "921025560268342", "021024620943221", "345675390223452", "345673782649576")
        
        ReDim txt_sort(UBound(txt))
        For i = LBound(txt) To UBound(txt)
            txt_sort(i) = Format(Mid(txt(i), 6), "0000000000")
            c.Add txt(i), txt_sort(i)
        Next i
        
        txt_sort = Split(Sort(txt_sort), ",")
        For i = 0 To c.Count - 1
           Debug.Print c.Item(Format((txt_sort(i)), "0000000000"))
        Next i
        
    End Sub这个是用集合的方法