Duplicate

2018年12月02日

首頁 | Thiessen Polygon | Collection object in vb 6 | Duplicate | Offset a curve | Ellipse | ImplicitFunction | get polygon | NonLineearSystemEquations | Get Polygon from FloodFill | UDT Pattern Brush in vb | Using VB NET predefined Pattern brush and known colors | VB NET extFloodfill

上次修改此網站的日期: 2018年12月02日

Sort of String/Number by Class Collection in VB 6.0(VB NET)

 

VB Net offers method Array.Sort() to sort an array, and Array.Reverse() to reverse an array. To sort a two dimensional or three dimesional array,VB Net dont support a direct method to sort a 2/3 dmensional array. Vb 6.0 dont offer any method to sort and duplicate an

Array. You may get a quick sort progrm in vb6.0 from net,in this article we will dicuss methods to sort an array or duplicate an array by class Collection.

 

object.Add item, [key as object], [before as object], [after as object]

 

To initial a collection in VB 6.0, we use

Set Object=nothing in VB NET we use Object.clear

 

The snippet code shown following is upgrading from VB 6.0. Sub SortNum2_Duplicate() can be used to sort and remove duplicaled a n_dimensional array.

 

 

Private Sub SortNum1(ByRef collMain As Collection)

           Dim i, j As Integer

           Dim collTpt As New Collection

           Dim collTptP As New Collection

           Dim testStrB, testStrA, testStrC As Double

        collTpt.Clear() 'collTpt = Nothing

           collTpt.Add("-99999999999999")

           collTpt.Add("99999999999999")

          

           For i = 1 To collMain.Count()

            testStrA = Val(collMain.Item(i))

                For j = 1 To collTpt.Count() - 1

                testStrB = Val(collTpt.Item(j))

                testStrC = Val(collTpt.Item(j + 1))                 

                     If testStrA >= testStrB And testStrA <= testStrC Then

                           collTpt.Add(collMain.Item(i),  ,  , j)                         

                           GoTo nextA

                     End If

                Next j

nextA:

           Next i

          

           collTpt.Remove(1)

           collTpt.Remove(collTpt.Count())     

           collMain = collTpt  

 

End Sub

Private Sub SortStr_Duplicate(ByRef collMain As Collection)

           Dim i, j As Integer

           Dim collTpt As New Collection

           Dim collTptP As New Collection

           Dim testStrB, testStrA, testStrC As String

        collTpt.Clear() 'set collTpt = Nothing

           collTpt.Add("0")

        collTpt.Add("ZZZZZZZZZZZZZ")

           For i = 1 To collMain.Count()

            testStrA = collMain.Item(i)

               

                For j = 1 To collTpt.Count() - 1

                testStrB = collTpt.Item(j)

                testStrC = collTpt.Item(j + 1)

                     If testStrA > testStrB And testStrA < testStrC Then

                           ' MsgBox ("yes")

                    collTpt.Add(collMain.Item(i), , , j)

                           GoTo nextA

                     End If

                Next j

nextA:

           Next i

          

           collTpt.Remove(1)

        collTpt.Remove(collTpt.Count())

        collMain = collTpt

     End Sub

Private Sub SortNum1_Duplicate(ByRef collMain As Collection)

           Dim i, j As Integer

           Dim collTpt As New Collection

           Dim collTptP As New Collection

        Dim testStrB, testStrA, testStrC As Double

        collTpt.Clear() 'set collTpt = Nothing

           collTpt.Add("-99999999999999")

           collTpt.Add("99999999999999")

          

           For i = 1 To collMain.Count()

            testStrA = Val(collMain.Item(i))

               

                For j = 1 To collTpt.Count() - 1

                testStrB = Val(collTpt.Item(j))

                testStrC = Val(collTpt.Item(j + 1))

                    

                     If testStrA > testStrB And testStrA < testStrC Then

                           'MsgBox ("yes")

                           collTpt.Add(collMain.Item(i),  ,  , j)

                          

                           GoTo nextA

                     End If

                Next j

nextA:

           Next i

         

           collTpt.Remove(1)

           collTpt.Remove(collTpt.Count())

          

           collMain = collTpt

          

     End Sub

 

Private Sub SortNum2_Duplicate(ByRef collMain As Collection, ByRef collApend As Collection)

 

        Dim i, j As Integer

        Dim collTpt As New Collection

        Dim collTptP As New Collection

        Dim testStrB, testStrA, testStrC As Double

        Dim testStrBP, testStrAP, testStrCP As Double

        collTpt.Clear() 'collTpt = Nothing

        collTptP.Clear() 'collTptP = Nothing

        collTpt.Add("-99999999999999")

        collTpt.Add("99999999999999")

        collTptP.Add("-99999999999999")

        collTptP.Add("99999999999999")

        For i = 1 To collMain.Count()

            testStrA = Val(collMain.Item(i))

            testStrAP = Val(collApend.Item(i))

            For j = 1 To collTpt.Count() - 1

                testStrB = Val(collTpt.Item(j))

                testStrC = Val(collTpt.Item(j + 1))

                testStrBP = Val(collTptP.Item(j))

                testStrCP = Val(collTptP.Item(j + 1))

                If testStrA > testStrB And testStrA < testStrC Then

                    'MsgBox ("yes")

                    collTpt.Add(collMain.Item(i), , , j)

                    collTptP.Add(collApend.Item(i), , , j)

                    GoTo nextA

                End If

            Next j

nextA:

        Next i

 

        collTpt.Remove(1)

        collTpt.Remove(collTpt.Count())

        collTptP.Remove(1)

        collTptP.Remove(collTptP.Count())

        collMain = collTpt

        collApend = collTptP

    End Sub

VB_VB NET: chday169

Name(您的大名)
E_MAIL(您的電子信箱)
Comment or Suggestion(您想反應的狀況,建議,或諮詢事項)
首頁