Click here to Skip to main content
15,890,438 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: List of error codes and matching error descriptions in vb.net Pin
Dave Kreskowiak26-Apr-13 12:17
mveDave Kreskowiak26-Apr-13 12:17 
GeneralRe: List of error codes and matching error descriptions in vb.net Pin
Dave Kreskowiak26-Apr-13 12:19
mveDave Kreskowiak26-Apr-13 12:19 
Questiontextbox Pin
Member 994134324-Apr-13 22:10
Member 994134324-Apr-13 22:10 
AnswerRe: textbox Pin
Simon_Whale24-Apr-13 23:00
Simon_Whale24-Apr-13 23:00 
GeneralRe: textbox Pin
Member 994134324-Apr-13 23:53
Member 994134324-Apr-13 23:53 
GeneralRe: textbox Pin
Simon_Whale24-Apr-13 23:58
Simon_Whale24-Apr-13 23:58 
AnswerRe: textbox Pin
Eddy Vluggen25-Apr-13 0:29
professionalEddy Vluggen25-Apr-13 0:29 
QuestionSort a Custom Class Collection in VB6 Pin
KeithF23-Apr-13 23:41
KeithF23-Apr-13 23:41 
Hi Folks,

I am having difficulty sorting a custom class based collection on two fields and am wondering if anyone can assist me. I have a class that looks like so:

VB
Class myClass

private ID as String
private Name as String
private TK as String
private Di as String
private M as String

End Class


Using this class i add to a Collection a number of items, e.g.

VB
Private colClass As Collection
Private clsTheClass As myClass


Set colClass = New Collection
    
    Set clsTheClass = New myClass
    clsTheClass.Name = "A"
    clsTheClass.TKs = "100"
    clsTheClass.Di = "5"
    clsTheClass.ID = "1"
    clsTheClass.M = "9"

    colClass.Add clsTheClass


What i end up with it is a collection that looks like so after adding all the items:

VB
ID  |Name   |TK     |Di    |M
1    A       100     5      9
2    B       100     3      9
3    C       10      5      9
4    D       10      7      9
5    E       10      1      9
6    F       400     9      5
7    F       400     4      5


I need to sort the collection On TK, and then DI. That should make the collection look like this:

VB
ID	|Name	|TK	|Di	|M
6	 F	 400	 9	 5
7	 F	 400	 4	 5
1	 A	 100	 5	 9
2	 B	 100	 3	 9
4	 D	 10	 7	 9
3	 C	 10	 5	 9
5	 E	 10	 1	 9



I am currently using this method to sort on TK, but i cannot get it to work how i need the output:

VB
Public Sub SortCollection(ColVar As Collection)
    Dim oCol As Collection
    Dim i As Integer
    Dim i2 As Integer
    Dim iBefore As Integer
    
    If Not (ColVar Is Nothing) Then
    
        If ColVar.Count > 0 Then
        
            Set oCol = New Collection
            
            For i = 1 To ColVar.Count
            
                If oCol.Count = 0 Then
                    oCol.Add ColVar(i)
                Else
                    iBefore = 0
                    
                    For i2 = oCol.Count To 1 Step -1
                    
                        If CLng(ColVar(i).TK) < CLng(oCol(i2).TK) Then
                            iBefore = i2
                        Else
                            Exit For
                        End If
                        
                    Next
                    
                    If iBefore = 0 Then
                        oCol.Add ColVar(i)
                    Else
                        oCol.Add ColVar(i), , iBefore
                    End If
                    
                End If
                
            Next

	    'WE now have it sorted by TK in Asc order so we need to reverse it

            
            'Reverse the collection
            Dim MyNewCol As New Collection
            Dim obj As Object
            For Each obj In oCol
                If MyNewCol.Count > 0 Then
                    MyNewCol.Add Item:=obj, before:=1
                Else
                    MyNewCol.Add Item:=obj
                End If
            Next
            
            Set ColVar = MyNewCol
            Set oCol = Nothing
            
        End If
        
    End If
    
End Sub


Anyone got any pointers as to what i need to change in the sort routine?

Thanks In Advance
AnswerRe: Sort a Custom Class Collection in VB6 Pin
_Marshall26-Apr-13 5:31
_Marshall26-Apr-13 5:31 
AnswerRe: Sort a Custom Class Collection in VB6 Pin
PrissySC26-Apr-13 12:53
PrissySC26-Apr-13 12:53 
AnswerRe: Sort a Custom Class Collection in VB6 Pin
Roy Heil3-Jun-13 10:34
professionalRoy Heil3-Jun-13 10:34 
QuestionHow to make main window invisible in VB for Windows CE? Pin
Member 989133422-Apr-13 21:45
Member 989133422-Apr-13 21:45 
AnswerRe: How to make main window invisible in VB for Windows CE? Pin
dusty_dex22-Apr-13 23:27
dusty_dex22-Apr-13 23:27 
GeneralRe: How to make main window invisible in VB for Windows CE? Pin
Member 989133423-Apr-13 2:16
Member 989133423-Apr-13 2:16 
GeneralRe: How to make main window invisible in VB for Windows CE? Pin
Eddy Vluggen23-Apr-13 2:40
professionalEddy Vluggen23-Apr-13 2:40 
GeneralRe: How to make main window invisible in VB for Windows CE? Pin
dusty_dex23-Apr-13 2:51
dusty_dex23-Apr-13 2:51 
GeneralRe: How to make main window invisible in VB for Windows CE? Pin
Member 989133424-Apr-13 3:35
Member 989133424-Apr-13 3:35 
GeneralRe: How to make main window invisible in VB for Windows CE? Pin
dusty_dex24-Apr-13 4:08
dusty_dex24-Apr-13 4:08 
GeneralRe: How to make main window invisible in VB for Windows CE? Pin
Member 989133425-Apr-13 3:50
Member 989133425-Apr-13 3:50 
GeneralRe: How to make main window invisible in VB for Windows CE? Pin
dusty_dex23-Apr-13 2:45
dusty_dex23-Apr-13 2:45 
QuestionVery long rtf string loading into RTB, and ContextSwitchDeadlock Pin
treddie22-Apr-13 13:13
treddie22-Apr-13 13:13 
AnswerRe: Very long rtf string loading into RTB, and ContextSwitchDeadlock Pin
Dave Kreskowiak22-Apr-13 14:05
mveDave Kreskowiak22-Apr-13 14:05 
GeneralRe: Very long rtf string loading into RTB, and ContextSwitchDeadlock Pin
treddie22-Apr-13 16:39
treddie22-Apr-13 16:39 
QuestionGlobal Hotkey Pin
Member 878710722-Apr-13 11:01
Member 878710722-Apr-13 11:01 
AnswerRe: Global Hotkey Pin
Dave Kreskowiak22-Apr-13 14:08
mveDave Kreskowiak22-Apr-13 14:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.