Reading From and Writing To text files

B

Bre-x

Hi,
I need to open a text file

if my code finds on the 3 Line (Always the 3 Line)
the text "(FN-", I need to replace it with "(FX-"

if the finds something else
I need to insert a line after the 2 and enter "(FX-"

Is there a way to do this?



Function insert_fnpath()
Dim fso As New Scripting.FileSystemObject
Dim thepath As String
Dim ftext
Dim ntext

thepath = "N:\1CNC\DATA\625\FISCON0100\6252018.txt"

Set ftext = fso.OpenTextFile(thepath, ForReading)

x = ftext.ReadLine
ftext.SkipLine
x = ftext.Read(4)
ftext.Close

Select Case x

Case "(FN-"
'Overwrite line with "(FX-)


Case Else
'Insert New Line after Line 2

End Select

Set fso = Nothing

end Function
 
L

Larry Daugherty

Look in VBA Help for the Open statement. It gives you enough
information to manage the file I/O. You need to use VBA to manipulate
the strings and do the rest of what you want.

The File I/O components work in all dialects of BASIC.

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top