01-08-2004, 06:28 PM
hey I got a rather complicated question here...I have my text file and in it are 2 fields..one is my name field and the other is the age field. In my vb program the name field is shown in my list box, however it is sorted alphabetically. I want to order it by the age but have been unsuccessful so far.
I have this:
but I want this sorted by the age column..is there an easy way of doing this? Thanks
01-08-2004, 06:50 PM
you could sort it yourself by age and then when you have a sorted array assign it to the listbox and it will keep your array index so that it appears in the same way you sorted it.
01-08-2004, 06:56 PM
Open the text file and read the line. Assuming comma separated, use the Split() function to split the line. Put name into an array and age into a separate array. Assign values to the array using the same index:
x = 0
Do until end of file
read first line
split line on comma
add to aryName[x]
add to aryAge[x]
Then, you can use a bubble sort on the Age array, and each swap, swap the corresponding Name array. Now the arrays are sorted by by age.
This is called parallel arrays. Just retrieve info using the same variable for an index like aryName(x) and aryAge(x).
In class now...can only give u pseudocode :)
01-09-2004, 12:53 AM
What does your look like? nama and age are coupled?
to me (manual) sorting is easy (though i haven't done it in a long time
(so it could prove more difficult)
I have a file that's read into an array of 2 columns. That way I can sort
the arrat according to each column when desired. When displayed in a Listview VB can sort for you.
other wise I'd suggest forst sorting then adding to the listbox
if you have more questions, just ask