Sign in to follow this  
Followers 0
wizzardking

how to put a text file into alpha order?

5 posts in this topic

Ok, heres the situation,

I'm creating a mailing list by letting people comeup to a computer at a show and enter thier email address into an input box, then the program writes the email address to a standard textfile using filewriteline etc etc..

So now I got this huge email database (about 500 names not that huge eh) and I want to put it into alpha order, but not just displyed if read into an array but actually rewrite the file in alpha order..

When I started this I thought this will be easy I did this in like 6th grade with trsbasic.. (Ok showing my age) but now I can't figure out the logic loop to save my life.. PLEASE HELP!!

Here's the sloppy code I have so far...

#include <GUIConstants.au3>

$a =0

GUICreate("My GUI") ; will create a dialog box that when displayed is centered

GUISetHelp("notepad") ; will run notepad if F1 is typed

Opt("GUICoordMode",2)

GUICtrlCreateLabel ("Email", 10, 30, 50) ; first cell 50 width

$line1 = GUICtrlCreateInput ("", 0, -1, 300, 20)

GUICtrlCreateLabel ("Done", -350, 0) ; next line

$line2 = GUICtrlCreateInput ("", -250, -1, 40, 20)

$line3 = GUICtrlCreateProgress (10,40,200,20,$PBS_SMOOTH)

GUISetState () ; will display an empty dialog box

$file = FileOpen("c:\emaillist.dat", 0)

; Check if file opened for reading OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

$a=0

Do ;establish counter

$a = $a + 1

$b = FileReadLine($file)

If @error = -1 Then ExitLoop

until 2=1

FileClose($file)

$counter = $a

$a = 0

For $d = 1 to $counter

$file = FileOpen("c:\emaillist.dat", 0)

$file1 = FileOpen("c:\emaillist.txt", 2)

EndIf

For $a = 1 to $counter

$b = FileReadLine($file)

If @error = -1 Then ExitLoop

$line = FileReadLine($file)

GUICtrlSetData($line2, $a)

If $b > $line then

$c = $b

$b = $line

$line = $c

EndIf

FileWriteLine($file1,$:whistle:

FileWriteLine($file1,$line)

Next

GUICtrlSetData($line1, $d)

FileClose($file)

FileClose($file1)

FileDelete("c:\emaillist.dat")

FileMove("c:\emaillist.txt","c:\emaillist.dat")

GUICtrlSetData ($line3,$d / $counter)

Next

As you can see my coding is very barbaric but usually works well.... when I'm not brain farting anyway..

Share this post


Link to post
Share on other sites



_FileReadToArray()

_ArraySort()

_FileWriteFromArray()

OMG duh.. like i said brain farting.. thanx i'll work it this week!

Share this post


Link to post
Share on other sites

well to sort it alphabetically if the addresses are entered at different intervals, not all at once, you have to rewrite the file containing them from time to time with what xcal wrote.


Share this post


Link to post
Share on other sites

well to sort it alphabetically if the addresses are entered at different intervals, not all at once, you have to rewrite the file containing them from time to time with what xcal wrote.

actually the files will be on several computers then we merge them after the events and then need them in alpha order so we would have a complete dbase to work with.

and it worked like a charm too!! Thanx a bunch all...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0