Need help sorting strings
I wrote a membership program for our local senior center but I can't figure out how to create a alphabetized file so I can send it to a printer.
For instance:
File Names.dat contains
Mary
Jack
Sally
Andrew
I need to create a new alphabetized file.
I know a simple bubble sort routine will do this but I don't know how to do it. Can someone please help me? I'm using VB5.0 :confused:
Re: Need help sorting strings
The quickest way without any code is to use Listbox control with Sorted proerty = True.
However, if you wish not to use it then load names into array and use sort algorithm similar to what's posted in this thread.
Re: Need help sorting strings
I added a commandbutton on a new form and added the follwowing code to the commandbutton:
Code:
Private Sub Command1_Click()
Shell "Sort C:\FileA.txt /O C:\FileB.txt"
End Sub
That will work on windows 2000, XP and VISTA.
I created FileA.txt with content:
Mary
Jack
Sally
Andrew
I then executed the code and it created FileB with the follwing content:
Andrew
Jack
Mary
Sally
Edit
The above code obviously assumes your original file already existed e.g.: Names.dat.
Re: Need help sorting strings
Thanks RhinoBull, I didn't know it was that easy. As they say, "If you don't use it you lose it" The program I'm creating is the first since I retired 10 years ago so I'm fumbling my way through it.