Click to See Complete Forum and Search --> : space delimited text file


Andrew
November 27th, 1999, 09:29 AM
I am working on a subroutine to convert space-delimited files to semicolon-delimited files. Right now the file looks something like this:

Adam Smith 45 Cherry St. 789-0098
Susan Sarandon 123 123rd Avenue 555-5555
Walter Matthau 54 Hollywood Blvd. 123-4567

Right now I am using the code

[vbcode]
Open CommonDialog1.Filename For Input as #File1
Line Input #File1, strText

Open CommonDialog2.Filename For Output as #File2
Print #File2, Texto

Obviously all this does is copy the file but unfortunately that is about the extent of my VB experience. I need a subroutine that will read the file, replace the white spaces between columns with a ";" and also return the column length (e.g. the number of spaces between the A of Adam Smith and the first number of his phone number).

any suggestions will be GREATLY appreciated!

Thanks,

Andrew

Allen Noakes
November 27th, 1999, 11:47 PM
Andrew,

The following function will replace all " " with ";"
Open CommonDialog1.Filename For Input as #File1
Line Input #File1, strText

strText = Replace(strText, " ", ";")

There is documentation on MSDN to explain more.


The part of counting the replacements could be done like the following:

Dim I as Long
Dim J as Long

I = 1
Do Until I = 0

I = InStr(I + 1, strText, ";")
If I <> 0 Then
J = I
End If

Loop

Crude but it works in a sticky situation.

Allen Noakes
VB Programmer/Analyst
Dames & Moore
misan@dames.com