|
-
Apr 6th, 2000, 06:54 AM
#1
Thread Starter
Banned
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
-
Apr 6th, 2000, 07:19 AM
#2
Hyperactive Member
Can you not just rearrange your arrays?
i.e:
x(1) = first name
x(2) = last name
x(3) = birthday
etc....
-
Apr 6th, 2000, 10:54 AM
#3
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|