Hello all,

I have an application that simply takes a formatted text file and replaces a phone number in it. The user just simply adds the phone number and then click on the command button and it reads the file into memory, replaces the string, and then writes it back to file. It does everything Just great!

My problem is the fact that it cuts ALL my whitespaces and formatting from the file. If this file is off by one whitespace, my decoder will not work at all. My file goes from 9k to 2k because this code cuts out all my white spaces. Anyone have any ideas how I can accomplish my mission while keeping the file format intact? Here is my code:

Option Explicit

Private Sub Command1_Click()
Dim strTextFile As String
Dim strTextLine As String
Dim strPhoneNumber As String

strPhoneNumber = Text1.Text ' Get the phone number

Open "C:\temp\Test.txt" For Input As #1 ' Open file.
Do While Not EOF(1) ' Loop until end of file.
Line Input #1, strTextLine ' Read line into variable.
strTextFile = strTextFile & strTextLine & vbCrLf ' Collect the input file.
Loop
Close #1 ' Close file.

strTextFile = Replace(strTextFile, "<PhoneNumber>", strPhoneNumber) 'adds the public text vatable that the user input overwriting the <PhoneNumber> text

Open "C:\temp\Test.txt" For Output As #1
Print #1, strTextFile
Close #1

End Sub


Timothy H. Schilbach
Alpha Omega Design Inc.
[email protected]