Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2005

Tip: Looking for answers? Try searching our database.

Reorder values in dynamicaly created WordBasic Listbox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ben - 01 Jun 2005 12:18 GMT
Hi

We have many macros developed in Wordbasic.

Is it possible to easily reorder the values already in these listboxes.

Any advice would be much appreciated.

Thanks
B
Jonathan West - 01 Jun 2005 16:27 GMT
In what way do you want them re-ordered? Sorted perhaps?

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

> Hi
>
[quoted text clipped - 6 lines]
> Thanks
> B
Ben - 01 Jun 2005 19:27 GMT
Sorry, yes alphabetically sorted.

Many thanks
B

> In what way do you want them re-ordered? Sorted perhaps?
>
[quoted text clipped - 8 lines]
>> Thanks
>> B
Jonathan West - 03 Jun 2005 11:42 GMT
> Sorry, yes alphabetically sorted.

Hi Ben,

OK, the simplest thing is to do the following.

1. Extract the contents of the listbox into a Variant that contains an
array, something like this

Dim vArray as Variant
vArray = ListBox1.List

vArray now contains a 2-dimensional array containing all the elements of the
listbox. If the listbox has only one column, you access each element in the
form vArray(n, 0) to get at the nth element (counting from zero)

2. Sort the array. There are plenty of routines on the web for sorting. If
you plug the words VB and Quicksort into a Google search, you will come
across plenty of them. The code may have to be modified to allow for the
fact that you are sorting a 2-d array even though it has only one column.
You can write your own sort routine if you want to, but the Quicksort code
samples that are available on the web are usually the fastest.

3. Put the sorted array back into the listbox. This is easily done

ListBox1.List = vArray

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org 

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.