How does one sort the contents of a Word 97 combobox once the it’s populated?
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Array Sort
Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Array Sort
- This topic has 20 replies, 6 voices, and was last updated 24 years, 3 months ago.
Viewing 1 reply threadAuthorReplies-
H. Legare Coleman
AskWoody Plus -
WSKevin
AskWoody Lounger -
WSjscher2000
AskWoody Lounger -
WSgwhitfield
AskWoody LoungerMarch 15, 2001 at 2:16 am #518927Not a native way.
What problems were there in the Word2000 Wordbasic.SortArray?
Have you chec ked out Charlotte’s example for a way to sort? (You no doubt have your own anyway)
-
WSjscher2000
AskWoody LoungerMarch 15, 2001 at 2:38 am #518936I think the WordBasic.SortArray method wasn’t supported, at least in the templates I was creating. Not sure why.
Actually, I don’t have my own sort routine; somehow, the stuff miraculously turned out to be sorted when it displayed in the ListBox, so I never had to write one.
Thanks for the link, though, you never know…
-
WSgwhitfield
AskWoody Lounger -
WSGary Frieder
AskWoody LoungerMarch 15, 2001 at 4:11 am #518950If the items were by chance, members of a collection, there seems to be some built-in sorting.
Here’s an example from something I’m working on right at the moment:If you go into a document and insert bookmarks around the first three paragraphs like so:
Bookmark2 goes here
Bookmark3 goes here
Bookmark1 goes hereAnd then run code like this:
With lstBmkNames
For n = 1 To objBmks.Count
.AddItem objBmks(n)
Next n
End WithWhat will display in the ListBox will be:
Bookmark1
Bookmark2
Bookmark3So it seems that collections internally sort themselves by name, regardless of the order in which the items actually occur in the document.
(You might have already known this one, but it was new to me! ) -
WSjscher2000
AskWoody LoungerMarch 15, 2001 at 5:29 am #518963Okay, there apparently wasn’t a miracle. I was sorting my array of folder names, because of this advice in the help under Dir:
Tip Because file names are retrieved in no particular order, you may want to store returned file names in an array, and then sort the array.
In fact, though, my array turned out to be nicely alphabetical without me doing any work. I think it is the way Win98 interacts with NT4 server, since I get the same results at a DOS prompt. Just dumb luck!
-
WSGary Frieder
AskWoody LoungerMarch 15, 2001 at 5:51 am #518978Ah, that reminds me! Why FileSearch is better than Dir:
(From VBA help:)
FileSearch object: Begins the search for the specified files.
Syntax 1
expression.Execute(SortBy, SortOrder, AlwaysAccurate)
expression Required. An expression that returns a FileSearch object.
SortBy Optional Variant. The method used to sort the returned files. Can be one of the following MsoSortBy constants: msoSortbyFileName, msoSortbyFileType, msoSortbyLastModified, or msoSortbySize.
SortOrder Optional Variant. The order in which the returned files are sorted. Can be either of the following MsoSortOrder constants: msoSortOrderAscending or msoSortOrderDescending.
AlwaysAccurate Optional Boolean. True to have the file search include files that have been added, modified, or deleted since the file index was last updated. The default value is True.
===========================
An optional SortBy method!!
And as an added bonus, the .FoundFiles object is an array.
-
-
-
-
WSchrisgreaves
AskWoody LoungerMarch 14, 2001 at 9:53 pm #518855Public Function SortListBox(lb As ListBox, intCol As Integer) If lb.ListCount > 0 Then Dim strar() As String ReDim strar(lb.ListCount - 1, lb.ColumnCount - 1) Dim lngRow As Long Dim intColumn As Integer 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 Call QCSort(strar, 0, UBound(strar, 1), False, intCol) For lngRow = 0 To lb.ListCount - 1 For intColumn = 0 To lb.ColumnCount - 1 lb.List(lngRow, intColumn) = strar(lngRow, intColumn) Next intColumn Next lngRow Else End If End Function
Public Function QCSort(strList() As String, ByVal lLbound As Long,_ ByVal lUbound As Long, ByVal boolCaseSensitive As Boolean, _ intColumn As Integer) ' March 3rd Chris Greaves Implemented a Column key (hence qCsort) Dim strTemp As String Dim strBuffer() As String Dim lngCurLow As Long Dim lngCurHigh As Long Dim lngCurMidpoint As Long lngCurLow = lLbound ' Start current low and high at actual low/high lngCurHigh = lUbound If lUbound <= lLbound Then Exit Function ' Error! lngCurMidpoint = (lLbound + lUbound) 2 ' Find the approx midpoint of the array ' Pick as a starting point (we are making ' an assumption that the data *might* be in semi-sorted order already! strTemp = MyUCase(strList(lngCurMidpoint, intColumn), boolCaseSensitive) Do While (lngCurLow <= lngCurHigh) Do While MyUCase(strList(lngCurLow, intColumn), boolCaseSensitive) < strTemp lngCurLow = lngCurLow + 1 If lngCurLow = lUbound Then Exit Do Loop Do While strTemp < MyUCase(strList(lngCurHigh, intColumn), boolCaseSensitive) lngCurHigh = lngCurHigh - 1 If lngCurHigh = lLbound Then Exit Do Loop If (lngCurLow <= lngCurHigh) Then ' if low is <= high then swap Call SwapRows(strList, lngCurLow, lngCurHigh) lngCurLow = lngCurLow + 1 ' CurLow++ lngCurHigh = lngCurHigh - 1 ' CurLow-- End If Loop If lLbound < lngCurHigh Then ' Recurse if necessary QCSort strList(), lLbound, lngCurHigh, boolCaseSensitive, intColumn End If If lngCurLow < lUbound Then ' Recurse if necessary QCSort strList(), lngCurLow, lUbound, boolCaseSensitive, intColumn End If 'Sub TESTQCSort() 'Dim strar(6, 3) As String 'strar(0, 0) = "january" 'strar(0, 1) = "february" 'strar(0, 2) = "march" 'strar(0, 3) = "april" 'strar(1, 0) = "may" 'strar(1, 1) = "june" 'strar(1, 2) = "july" 'strar(1, 3) = "august" 'strar(2, 0) = "september" 'strar(2, 1) = "october" 'strar(2, 2) = "november" 'strar(2, 3) = "december" 'strar(3, 0) = "Monday" 'strar(3, 1) = "Tuesday" 'strar(3, 2) = "Wednesday" 'strar(3, 3) = "Thursday" 'strar(4, 0) = "Friday" 'strar(4, 1) = "Saturday" 'strar(4, 2) = "Sunday" 'strar(4, 3) = "january" 'strar(5, 0) = "february" 'strar(5, 1) = "march" 'strar(5, 2) = "april" 'strar(5, 3) = "may" 'strar(6, 0) = "june" 'strar(6, 1) = "july" 'strar(6, 2) = "august" 'strar(6, 3) = "september" 'Selection.TypeParagraph 'Debug.Print " " 'Call DumpArray(strar) 'Call QCSort(strar, LBound(strar, 1), UBound(strar, 1), False, 2) 'Selection.TypeParagraph 'Debug.Print " " 'Call DumpArray(strar) 'End Sub End Function
-
WSKevin
AskWoody LoungerMarch 14, 2001 at 10:00 pm #518858Cool dude, but where’s the SwapRows function? Thanks though for that time saver. I tell you what. I’ll play around with your code and replace your SwapRows with a swap routine that uses the Windows API CopyMemory function:
Private Declare Sub CopyMemory Lib “kernel32” Alias “RtlMoveMemory” (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
…if I have time.
-
WSchrisgreaves
AskWoody LoungerMarch 14, 2001 at 10:10 pm #518860Public Function SwapRows(strList() As String, lngCurLow As Long, lngCurHigh As Long) Dim lngCols As Long lngCols = UBound(strList, 2) Dim strBuffer As String Dim lngC As Long For lngC = 0 To lngCols strBuffer = strList(lngCurLow, lngC) strList(lngCurLow, lngC) = strList(lngCurHigh, lngC) strList(lngCurHigh, lngC) = strBuffer Next lngC End Function
-
WSKevin
AskWoody Lounger -
WSchrisgreaves
AskWoody LoungerMarch 14, 2001 at 10:20 pm #518867You’re welcome. I’m not such a bad sort after all, eh?
You mentioned a (presumably) faster way to sort arrays, In-memory? I’d be interested in a simple example that I could then clone and pass off as my own (grin!). I do a lot of sorting of arrays, listboxes and internal arrays (as, for example, when I am dropping duplicate paragraphs of a document)
Perhaps we could be nice to the lounge and collaborate on a routine by private email and then publish it? Is that allowed?
-
WSKevin
AskWoody LoungerMarch 14, 2001 at 10:25 pm #518868 -
WSchrisgreaves
AskWoody Lounger -
WSKevin
AskWoody Lounger -
WSchrisgreaves
AskWoody Lounger -
WSKevin
AskWoody Lounger -
WSchrisgreaves
AskWoody Lounger
-
-
-
Viewing 1 reply thread -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Are Macs immune?
by
Susan Bradley
2 hours, 30 minutes ago -
HP Envy and the Function keys
by
CWBillow
2 hours, 59 minutes ago -
Microsoft : Removal of unwanted drivers from Windows Update
by
Alex5723
4 hours, 23 minutes ago -
MacOS 26 beta 1 dropped support for Firewire 400/800
by
Alex5723
4 hours, 40 minutes ago -
Unable to update to version 22h2
by
04om
4 hours, 59 minutes ago -
Windows 11 Insider Preview Build 26100.4482 (24H2) released to Release Preview
by
joep517
12 hours, 8 minutes ago -
Windows 11 Insider Preview build 27881 released to Canary
by
joep517
12 hours, 10 minutes ago -
Very Quarrelsome Taskbar!
by
CWBillow
3 hours, 17 minutes ago -
Move OneNote Notebook OFF OneDrive and make it local
by
CWBillow
1 day, 1 hour ago -
Microsoft 365 to block file access via legacy auth protocols by default
by
Alex5723
13 hours, 52 minutes ago -
Is your battery draining?
by
Susan Bradley
6 hours, 59 minutes ago -
The 16-billion-record data breach that no one’s ever heard of
by
Alex5723
3 hours, 59 minutes ago -
Weasel Words Rule Too Many Data Breach Notifications
by
Nibbled To Death By Ducks
1 day, 4 hours ago -
Windows Command Prompt and Powershell will not open as Administrator
by
Gordski
13 hours, 4 minutes ago -
Intel Management Engine (Intel ME) Security Issue
by
PL1
13 hours, 16 minutes ago -
Old Geek Forced to Update. Buy a Win 11 PC? Yikes! How do I cope?
by
RonE22
5 hours, 56 minutes ago -
National scam day
by
Susan Bradley
12 hours, 49 minutes ago -
macOS Tahoe 26 the end of the road for Intel Macs, OCLP, Hackintosh
by
Alex5723
8 hours, 58 minutes ago -
Cyberattack on some Washington Post journalists’ email accounts
by
Bob99
2 days, 6 hours ago -
Tools to support internet discussions
by
Kathy Stevens
18 hours, 44 minutes ago -
How get Group Policy to allow specific Driver to download?
by
Tex265
1 day, 21 hours ago -
AI is good sometimes
by
Susan Bradley
2 days, 13 hours ago -
Mozilla quietly tests Perplexity AI as a New Firefox Search Option
by
Alex5723
2 days, 3 hours ago -
Perplexity Pro free for 12 mos for Samsung Galaxy phones
by
Patricia Grace
3 days, 13 hours ago -
June KB5060842 update broke DHCP server service
by
Alex5723
3 days, 12 hours ago -
AMD Ryzen™ Chipset Driver Release Notes 7.06.02.123
by
Alex5723
3 days, 16 hours ago -
Excessive security alerts
by
WSSebastian42
2 days, 6 hours ago -
* CrystalDiskMark may shorten SSD/USB Memory life
by
Alex5723
4 days, 1 hour ago -
Ben’s excellent adventure with Linux
by
Ben Myers
15 hours, 47 minutes ago -
Seconds are back in Windows 10!
by
Susan Bradley
3 days, 12 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.