要求实现排序功能, 先号*号前面的数字按升序排列,然后按*号后面的数字按升序排序
后缀字母(一位或两位)忽略不计。
例:要求这样:
1*110
1*220
12*10
13*210
13*230
14*1
14*10
14*11f
14*12谢谢。

解决方案 »

  1.   


    你可以关注此贴的讨论:http://community.csdn.net/Expert/topic/3214/3214394.xml?temp=.6535608
      

  2.   

    主要思路,先用VAL取得最前面的数字,进行排序。
    然后用一个循环找出前面数字相同的项,分批排序具体就不写了
      

  3.   

    Dim str
    Dim ar(20, 250) As String
    str = Array("13*230", "14*1", "14*10", "1*110", "1*220", "12*10", "13*210", "14*11", "14*12")
    Dim i As Integer
    Dim a As Integer, b As Integer
    Dim ins As Integer
    For i = 0 To UBound(str)
        ins = VBA.InStr(str(i), "*")
        a = Left(str(i), ins - 1)
        b = Right(str(i), Len(str(i)) - ins)
        ar(a, b) = str(i)
    Next i
    For a = 0 To 20
        For b = 0 To 250
            If ar(a, b) <> vbNullString Then
                MsgBox ar(a, b)
            End If
        Next
    Next
      

  4.   

    这个函数是在EXCEL里用来排列A列各单元格内容的的,可以帮我修改一下吗?
      

  5.   

    一个另类的做法,利用一个数型控件,将前面的数字作为第一层节点
    而后面的数字做为后层节点,排序结果如下
    +1
       -----110
       -----220
    +12
       ------110
    +13
       -----210
       -----230
    +144
       ------1
       ------10
       ------11
       ------12
    这样做的目的纯粹是为了好玩,建议实际做时用字典,再在排序算法上做优化
    Private Sub Command4_Click()
    Dim str
    str = Array("13*230", "14*1", "14*10", "1*110", "1*220", "12*10", "13*210", "14*11", "14*12")
    Dim i As Integer
    Dim a As Integer, b As Integer
    Dim ins As Integer
    Dim NodX As Node
    Dim NodTemp As Node
    Dim NodSecond As Node
    Dim N As Integer
    TreeView1.Nodes.Add , , "Root", "根目录"
    For i = LBound(str) To UBound(str)
        With TreeView1
            ins = VBA.InStr(str(i), "*")
            a = Left(str(i), ins - 1)
            b = Right(str(i), Len(str(i)) - ins)
            If (.Nodes(1).Children > 0) Then
            
               Set NodTemp = .Nodes("Root").Child '在第一层按前面的数字排序
               N = NodTemp.FirstSibling.Index '取到第一个节点
               Do While (N <> NodTemp.LastSibling.Index)
                    If (a < CInt(Right(.Nodes(N).Key, Len(.Nodes(N).Key) - 1))) Then
                        '在该节点之前
                        Set NodX = .Nodes.Add(.Nodes(N), tvwPrevious, "N" & a, CStr(a))
                        .Nodes.Add .Nodes(NodX.Index), tvwChild, , CStr(b)
                        Exit Do
                    ElseIf (a = CInt(Right(.Nodes(N).Key, Len(.Nodes(N).Key) - 1))) Then
                        Set NodSecond = .Nodes("N" & a).Child
                        N = NodSecond.FirstSibling.Index '取到第一个节点
                        Do While (N <> NodSecond.LastSibling.Index)
                             If (b < CInt(.Nodes(N).Text)) Then
                                 '在该节点之前
                                 .Nodes.Add .Nodes(N), tvwPrevious, , CStr(b)
                                 Exit Do
                             End If
                             N = .Nodes(N).Next.Index
                        Loop
                        If (N = NodSecond.LastSibling.Index) Then
                             If (b < .Nodes(N).Text) Then
                                 .Nodes.Add .Nodes(N), tvwPrevious, , CStr(b)
                             Else
                                 .Nodes.Add .Nodes(N), tvwNext, , CStr(b) '插在最后
                             End If
                        End If
                        Exit Do
                    End If
                    N = .Nodes(N).Next.Index
               Loop
               If (N = NodTemp.LastSibling.Index) Then
                    If (a < CInt(Right(.Nodes(N).Key, Len(.Nodes(N).Key) - 1))) Then
                        Set NodX = .Nodes.Add(.Nodes(N), tvwPrevious, "N" & a, CStr(a))
                        .Nodes.Add .Nodes(NodX.Index), tvwChild, , CStr(b)
                    ElseIf (a = CInt(Right(.Nodes(N).Key, Len(.Nodes(N).Key) - 1))) Then
                         Set NodSecond = .Nodes("N" & a).Child
                        N = NodSecond.FirstSibling.Index '取到第一个节点
                        Do While (N <> NodSecond.LastSibling.Index)
                             If (b < CInt(.Nodes(N).Text)) Then
                                 '在该节点之前
                                 .Nodes.Add .Nodes(N), tvwPrevious, , CStr(b)
                                 Exit Do
                             End If
                             N = .Nodes(N).Next.Index
                        Loop
                        If (N = NodSecond.LastSibling.Index) Then
                             If (b < .Nodes(N).Text) Then
                                 .Nodes.Add .Nodes(N), tvwPrevious, , CStr(b)
                             Else
                                 .Nodes.Add .Nodes(N), tvwNext, , CStr(b) '插在最后
                             End If
                        End If
                    
                    Else
                        Set NodX = .Nodes.Add(.Nodes(N), tvwNext, "N" & a, CStr(a)) '插在最后
                        .Nodes.Add .Nodes(NodX.Index), tvwChild, , CStr(b)
                    End If
               End If
          
            
               Else
                    Set NodX = .Nodes.Add("Root", tvwChild, "N" & a, CStr(a))
                    .Nodes.Add .Nodes(NodX.Index), tvwChild, , CStr(b)
            End If
                End WithNext i    
    End Sub
      

  6.   

    excel 里表格的值是cells(i,j).value