Visual Basic (VB and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

 

Please read the DISCLAIMER.

Here is an INDEX to all the procedures.

You will probably need one copy of my GLOBAL DECLARATIONS.



Public Function SortListBox(lb As ListBox, intCol As Integer)
' Procedure :   SortListBox
' Description:  Sort the listbox on the specified column.
' By:           Chris Greaves Inc.
' Inputs:       ListBox, integer Column number.
' Returns:      None.
' Assumes:      Nothing
' Side Effects: The listbox may shrink.
' Tested:       by the calls shown below.
' Preserve the original list dimensions since we will be clearing the list.
    Dim lngListCount As Long
    lngListCount = lb.ListCount
    Dim lngColumnCount As Long
    lngColumnCount = lb.ColumnCount
    If lngListCount > 0 Then
        ' Build a string array to receive a copy of the listbox contents.
        Dim strAr() As String
        ReDim strAr(lb.ListCount - 1, lb.ColumnCount - 1)
        Dim lngRow As Long
        Dim intColumn As Integer
        ' Copy the listbox contents to the array.
        For lngRow = 0 To lb.ListCount - 1
            For intColumn = 0 To lb.ColumnCount - 1
                strAr(lngRow, intColumn) = lb.List(lngRow, intColumn)
            Next intColumn
        Next lngRow
        ' Sort the array
        Call QCSort(strAr, 0, UBound(strAr, 1), False, intCol)
        ' Read back the array; clear the listbox and drop duplicate 9sorted) entries.
        Dim strOld As String
        lb.Clear
        lb.ColumnCount = lngColumnCount
        For lngRow = 0 To lngListCount - 1
            If strOld = strAr(lngRow, intCol) Then ' found a duplicate on this column-key
            Else ' Not a duplicate; copy it back to the list.
                strOld = strAr(lngRow, intCol)
                lb.AddItem
                For intColumn = 0 To lngColumnCount - 1
                    lb.List(lb.ListCount - 1, intColumn) = strAr(lngRow, intColumn)
                Next intColumn
            End If
        Next lngRow
    Else
    End If
End Function

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Thursday, November 15, 2001

 

 

Hosted by www.Geocities.ws

1

Visual Basic (VB and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

 

Please read the DISCLAIMER.

Here is an INDEX to all the procedures.

You will probably need one copy of my GLOBAL DECLARATIONS.

Public Function SortListBox(lb As ListBox, intCol As Integer)
' Procedure :   SortListBox
' Description:  Sort the listbox on the specified column.
' By:           Chris Greaves Inc.
' Inputs:       ListBox, integer Column number.
' Returns:      None.
' Assumes:      Nothing
' Side Effects: The listbox may shrink.
' Tested:       by the calls shown below.
' Preserve the original list dimensions since we will be clearing the list.
    Dim lngListCount As Long
    lngListCount = lb.ListCount
    Dim lngColumnCount As Long
    lngColumnCount = lb.ColumnCount
    If lngListCount > 0 Then
        ' Build a string array to receive a copy of the listbox contents.
        Dim strAr() As String
        ReDim strAr(lb.ListCount - 1, lb.ColumnCount - 1)
        Dim lngRow As Long
        Dim intColumn As Integer
        ' Copy the listbox contents to the array.
        For lngRow = 0 To lb.ListCount - 1
            For intColumn = 0 To lb.ColumnCount - 1
                strAr(lngRow, intColumn) = lb.List(lngRow, intColumn)
            Next intColumn
        Next lngRow
        ' Sort the array
        Call QCSort(strAr, 0, UBound(strAr, 1), False, intCol)
        ' Read back the array; clear the listbox and drop duplicate 9sorted) entries.
        Dim strOld As String
        lb.Clear
        lb.ColumnCount = lngColumnCount
        For lngRow = 0 To lngListCount - 1
            If strOld = strAr(lngRow, intCol) Then ' found a duplicate on this column-key
            Else ' Not a duplicate; copy it back to the list.
                strOld = strAr(lngRow, intCol)
                lb.AddItem
                For intColumn = 0 To lngColumnCount - 1
                    lb.List(lb.ListCount - 1, intColumn) = strAr(lngRow, intColumn)
                Next intColumn
            End If
        Next lngRow
    Else
    End If
End Function

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Thursday, November 15, 2001

 

 

Hosted by www.Geocities.ws

1