Results 1 to 10 of 10

Thread: Alphabetizing Lists

  1. #1

    Thread Starter
    Hyperactive Member Zaphod64831's Avatar
    Join Date
    Mar 2000
    Posts
    268

    Post

    Does anyone have a code sample that will alphabetize a list? I am using a For Each loop to populate a list but the items all come out jumbled.

    Here's what it looks like now:
    Code:
    For Each Animation In Merlin.AnimationNames
       List1.AddItem Animation
    Next
    Can anyone help?
    Email: [email protected]

    Home Page: www.olemac.net/~hutch

    I'm bored, VERY bored, and I got bored with my sig. So I changed it to this.

  2. #2
    Guest
    Well here's a simple process. Put the word in a Temp textbox. Get the first letter of the word. Since each character has a number value, arrange each word in order from which even "number" is the smallest.

    For example, on the ASCII Chart, a = 97, b = 98 c = 99 d = 100 etc. etc.

  3. #3
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Lightbulb

    Just change the Sorted property of the ListBox to True.

  4. #4
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Code:
    For Each AnimationName In Character.AnimationNames
            ListBox.AddItem AnimationName
    Next
    and set it to sorted = true, for the listbox

  5. #5
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604

    how about for data arrays

    Hey guys, I have a similar problem.

    I made a small database that basically reads/write by a text file of the records. This kind of thing

    For intX = 0 to intNumRecords
    Write #1, strName(intX), strAddress(intX), strEmail(intX)...
    Next intX

    Question is: How can I alphabetize the strName() of a new
    record that is being added to the file and keep all records of the index intX intact (in other words re-writing the entire file now alphabetized with name , address, ....etc.
    still corresponding)?

    Has anybody done this already?

    Thanks .

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Question I put my qwestion here

    Does anyone know how listbox sorts? I have an app that use bubblesort but it goes exponentially slower, the more items i have. If anyone have a faster sorting method, like listbox, post back to me.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7
    Addicted Member Razzle's Avatar
    Join Date
    Jan 2000
    Location
    Berlin, Germany
    Posts
    161
    The fastest sorting algorithm is a Shellsort algorithm using a C++ DLL. you can use it e.g. to sort arrays.
    The source for the C++ DLL is:

    Code:
    #include <windows.h>
    /***********************************************************
    
    shellsort algorithm
    dllname : sort32.dll
    parameters: array, fieldelementcount
    
    ***********************************************************/
    void _stdcall sort(double a[], long n)
    {
    long k, i, j;
    double hM
      k = n/2
      while (k>0)
       { for (i=0; i<n-k; i++)
         { j=i;
           while (j>=0 && a[j]>a[j+k])
            { h=a[j]; a[j]=a[j+k]; a[j+k]=h; j=j-k; }
         }
         k = k/2;
        }
    }
    
    BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)
    { return TRUE; }
    to use this routine in a VB program:
    Code:
    Declare Sub sort Lib "sort32.dll" (field as Double, ByVal count&)
    [Edited by Razzle on 05-07-2000 at 07:12 AM]
    Razzle
    ICQ#: 31429438
    What is the difference between a raven?
    -The legs. The length is equal, especially the right one.

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Thanks, can anybody translate that to vb?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  9. #9
    Addicted Member Razzle's Avatar
    Join Date
    Jan 2000
    Location
    Berlin, Germany
    Posts
    161
    no problem

    Code:
    Sub sort_shell(a() as Variant)
    Dim n&, i&, j&, k&, h as Variant
     
      n =  Ubound(a)
      k = n \ 2
      While k > 0
        For i = 0 to n - k
         j = i
         While (j >= 0) And (a(j) > a(j + k))
           h = a(j)
           a(j) = a(j + k)
           a(j + k) = h
           If j > k Then 
             j = j - k
           Else
             j = 0
           End if
         Wend
        Next i
        k = k \ 2
       Wend
    End Sub
    [Edited by Razzle on 05-07-2000 at 07:49 AM]
    Razzle
    ICQ#: 31429438
    What is the difference between a raven?
    -The legs. The length is equal, especially the right one.

  10. #10
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Thanx again, i was thinking, why only double, because i'm sorting strings. Now variant looks much better
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width