VBSCript to parse text file

I'm an old school C programmer and would like to make the switch to VBScript. I know how to do this in C but i really would like to do this using VBscript. I have a text file with the following contents:
                                               8403 SE May Valley Rd Issaquah WA  98027

The info in the lines vary but once i have the basic script i can modify it to suite my needs. I want open a text file, read it, parse it and then write the results to another txt file. I would like to seperate out the individual address fields. (i.e. Street address, city, state, zip). I want to reformat the line with commas separating the fields and write this to another file. In C i would parse these lines in reverse (using the space as a delimiter). On some of the lines there is an account #at the end of the lines. the account # is prepended by the string: "Acct #".

Any help would be most appreciated. I don't have the luxury of time to learn VBScript from scratch.

ronfastI.T. DirectorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
I can give you code to open a file and read it line by line.
I can give you code to open a file and write to it line by line.

*** But how the heck can you realiably parse a line like that using just spaces?

How do you know where the address ends and the city begins?

What if the city has a space in it?


    8403 SE May Valley Rd Colorado Springs CO  98027

"Colorado Springs" is the city.  So how can you reliably know by just counting spaces when you have reached the end of the city?
ronfastI.T. DirectorAuthor Commented:
you can't really but all i want is for it to work for the majority of the records (i.e. city with no space). This will eliminate 90% of my work. I can handle doing the last 10% by hand.
Mike TomlinsonMiddle School Assistant TeacherCommented:
So you just need basic info on how to read/write files with VBScript?

Here is some bare bones code on how to read a file line by line and output lines to another file...

Dim source, target
source = "c:\source.txt"
target = "c:\target.txt"

Dim fso, f, f2
Const ForReading = 1, ForWriting = 2

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(source) Then
   Dim inputLine, outputLine
   Set f = fso.OpenTextFile(source, ForReading, False)
   Set f2 = fso.OpenTextFile(target, ForWriting, True)
   While Not f.AtEndOfStream
      inputLine= f.ReadLine
      ' analyze inputLine in here using String manipulation Left(), Mid(), Right(), Split(), Instr() etc...
      ' build outputLine so it looks as desired...

      f2.WriteLine outputLine
   Set f2 = Nothing
   Set f = Nothing
   MsgBox "Done"
   MsgBox source, vbOKOnly, "Source File Not Found"
End If
Set fso = Nothing

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.