sorting array values in alphabetical order 
Author Message
 sorting array values in alphabetical order

hi...

I have stored some strings in an array. When I need to print these
strings
I just loop through the array values like for i=1 to recordscount ...etc

Is there any way in which I can print these strings in alphabetical
order
finding which string has a smaller i value?

Kinda difficult huh ?

In any response...occurs..thanks in advance

Nikos



Mon, 23 Apr 2001 03:00:00 GMT  
 sorting array values in alphabetical order
Several options exist. If the number of strings is small, load them into a Listbox
with the .Sort Property True and print from the Listbox. Or, do a Bubble Sort on the
array prior to printing.

Quote:

>hi...
>I have stored some strings in an array. When I need to print these
>strings
>I just loop through the array values like for i=1 to recordscount ...etc
>Is there any way in which I can print these strings in alphabetical
>order
>finding which string has a smaller i value?
>Kinda difficult huh ?
>In any response...occurs..thanks in advance
>Nikos


***********************
Why am I riding in this Hand Basket and just where are we going?

Email: use glennmiy AT worldnet DOT att Dot net



Mon, 23 Apr 2001 03:00:00 GMT  
 sorting array values in alphabetical order
Nikos,

There are many ways for sorting arrays, but a cheap, quick and dirty one is
to create a (hidden) listbox with Sort property to True. Then put your array
in the listbox with AddItem, and read the sorted list out with List(Index)
into your array again.

John Tegelaar

Quote:

>hi...
>I have stored some strings in an array. When I need to print these
>strings
>I just loop through the array values like for i=1 to recordscount ...etc
>Is there any way in which I can print these strings in alphabetical
>order
>finding which string has a smaller i value?
>Kinda difficult huh ?
>In any response...occurs..thanks in advance
>Nikos




Mon, 23 Apr 2001 03:00:00 GMT  
 sorting array values in alphabetical order
Here is a nice fast Shellsort routine. First copy and paste the following
code into the (General) (Declarations) section of your Form (or a module).
Then if, for example, you have an array called MyArray then to sort it
simply use the code "ShellSort MyArray, Lbound (MyArray), Ubound (MyArray)".
You can also sort only parts of an array (a common requirement). For
example, if you have an array MyArray (500) then you can, if you wish, sort
only elements 100 to 180 by using "Shellsort MyArray, 100, 180). This
shellsort routine is very fast, especially on numbers of any kind or on
equal length strings. It will, of course, also work well on variable length
strings - but all sort routines which swap actual data slow down appreciably
when the length of such data is variable, because they have to shift lots of
bytes about in memory. You can speed up any sort routine tremendously on
variable length strings by sorting pointers to the data rather than the
actual data itself - but that's another story!

Hope this is of help to you.

Mike

Public Sub ShellSort(ByRef A() As Variant, ByVal Lb As Long, ByVal Ub As
Long)
Dim n As Long, h As Long
Dim i As Long, j As Long
Dim t As Variant
'
' ***** If you are using this routine to sort string data and you want it to
be case
' insensitive (ie "cat" comes before "Dog") then you must place the line
' "Option Compare Text" in the (general) (declarations) section of the Form
' or Module in which this routine is declared
*******************************
'
' We allow the user to send his own start and end positions to this routine
in
' case he wants to sort only part of the array (which is a common
requirement)
' so we must first check and adjust those parameters in case he has given
' us silly numbers!
If Ub > UBound(A) Then Ub = UBound(A)
If Lb < LBound(A) Then Lb = LBound(A)
If Lb >= Ub Then Exit Sub
'
' now sort array (from element lb to element ub)
' first calculate the largest increment
n = Ub - Lb + 1
h = 1
If n > 13 Then
  Do While h < n
    h = 3 * h + 1
  Loop
  h = h \ 3
  If h > (n * 0.8) Then h = h \ 3
End If
' repeatedly do an insertion sort using
' values of h from its initial value down
' to a value of 1
Do While h > 0
  For i = Lb + h To Ub
    t = A(i)
    For j = i - h To Lb Step -h
      If A(j) <= t Then Exit For
      A(j + h) = A(j)
    Next j
    A(j + h) = t
  Next i
  h = h \ 3
Loop
End Sub

Quote:

>hi...

>I have stored some strings in an array. When I need to print these
>strings
>I just loop through the array values like for i=1 to recordscount ...etc

>Is there any way in which I can print these strings in alphabetical
>order
>finding which string has a smaller i value?

>Kinda difficult huh ?

>In any response...occurs..thanks in advance

>Nikos




Tue, 24 Apr 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Sort strings in alphabetical order

2. Sort order - Edit Filter Sort or Quick Sort

3. Sorting an array into order

4. Sorting array in alphabetial order

5. to cross a table in alphabetical order

6. Printing documents in alphabetical order

7. Print documents in alphabetical order

8. Print documents in alphabetical order

9. Automatic alphabetical order

10. Alphabetical order

11. Help, dir : how to class files by alphabetical order

12. DBCombo to show fields in alphabetical order

 

 
Powered by phpBB® Forum Software