If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Reading From and Writing To text files
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 |
#2
|
|||
|
|||
Reading From and Writing To text files
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 -- -Larry- -- "Bre-x" wrote in message ... 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 |
Thread Tools | |
Display Modes | |
|
|