Results 1 to 3 of 3

Thread: Array / Sorting

  1. #1

    Thread Starter
    Banned
    Join Date
    Mar 2000
    Posts
    7
    I have an array named X with 17 strings in it. For an example, It looks like this:

    x(1) = birthday
    x(2) = last name
    x(3) = first name
    x(4) = address
    x(5) = state
    x(6) = zip code
    x(7) = city
    etc.....

    I want the order to be like this:

    first name
    last name
    birthday
    address
    city
    state
    zip code

    Programmaticaly, how can I sort the array to get it how I want? Is it possible to put my array X into another array and sort it?

    If so , can you please show me how?

    Thank you,

    'tard

  2. #2
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Glasgow,Scotland
    Posts
    281

    Can you not just rearrange your arrays?

    i.e:

    x(1) = first name
    x(2) = last name
    x(3) = birthday

    etc....

  3. #3
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ottawa,ON,Canada
    Posts
    217
    You can use a Bubble sort. Which allows you to run through a list of values and float the largest ones to the top of the list and the smallest ones to the bottom (or vice versa).

    Try using the following module:
    Code:
    Private Sub BubbleSort(asValues() As String)
       Dim iLimit As Integer
       Dim iStep As Integer
       Dim iCompare As Integer
       Dim sTemp As String
       
       iLimit = UBound(asValues) - 1
       
       For iStep = 0 To iLimit Step 1
          
          For iCompare = 0 To iLimit Step 1
             
             If StrComp(asValues(iCompare), asValues(iCompare + 1)) > 0 Then
                sTemp = asValues(iCompare)
                asValues(iCompare) = asValues(iCompare + 1)
                asValues(iCompare + 1) = sTemp
             End If
             
          Next iCompare
          
       Next iStep
       
    End Sub
    Now simply call the procedure and pass the array you want sorted, because arrays are passed by reference the array will be sorted when it returns.

    Hope this helps.

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