|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How can i output data between 2 strings to another fileI have a file which has some information starting with a heading like
Trial Balance for the months . I want to output all this information starting from this till the total line to another file usinf FSO and VB script. Would anyone know how to do this?I tried a real line after and instring search but it gies an error that Input ast end of file. Thanks in anticipation. Ajay Garg Show your code....
-- Show quoteHide quoteChris Hanscom - Microsoft MVP (VB) Veign's Resource Center http://www.veign.com/vrc_main.asp Veign's Blog http://www.veign.com/blog -- "AG" <ajay***@hotmail.com> wrote in message news:1139007180.940823.37060@o13g2000cwo.googlegroups.com... >I have a file which has some information starting with a heading like > Trial Balance for the months . > > I want to output all this information starting from this till the total > line to another file usinf FSO and VB script. > > Would anyone know how to do this?I tried a real line after and instring > search but it gies an error that Input ast end of file. > > > Thanks > in anticipation. > > > > Ajay Garg > startstring = "ASSOCIATION TOTALS BY ACCOUNT TYPE"
endstring = "TOTL" sData = ReadFile("C:\Documents and Settings\Owner.AJAYGARG\My Documents\ASSOCIATION TOTALS BY ACCOUNT TYPE.doc") startposition = InStr(sData, startstring) sData = Left(sData, startposition) endposition = InStr(sData, endstring) + Len(endstring) - 1 sData = Left(sData, endposition) WScript.echo sData Function ReadFile(FilePath) 'Given the path to a file, will return entire contents ' works with either ANSI or Unicode Dim FSO, CurrentFile Const ForReading = 1, TristateUseDefault = -2, _ DoNotCreateFile = False Set FSO = createobject("Scripting.FileSystemObject") If FSO.FileExists(FilePath) Then If FSO.GetFile(FilePath).Size>0 Then Set CurrentFile = FSO.OpenTextFile(FilePath, ForReading, _ False, TristateUseDefault) If CurrentFile.AtEndOfStream <> True Then ReadFile = CurrentFile.ReadAll WriteFile "C:\Documents and Settings\Owner.AJAYGARG\My Documents\ASSOCIATION TOTALS BY ACCOUNT TYPEf.doc", outData : CurrentFile.Close End IfEnd If End If End Function Sub WriteFile(FILEPATH, sData) 'writes sData to FilePath With CreateObject("Scripting.FileSystemObject")._ OpenTextFile(FilePath, 2, True) .Write sData: .Close End With End Sub VBS is not VB so you would be better off posting in the scripting newsgroup.
-- Show quoteHide quoteChris Hanscom - Microsoft MVP (VB) Veign's Resource Center http://www.veign.com/vrc_main.asp Veign's Blog http://www.veign.com/blog -- "AG" <ajay***@hotmail.com> wrote in message news:1139079092.709895.206310@g43g2000cwa.googlegroups.com... > startstring = "ASSOCIATION TOTALS BY ACCOUNT TYPE" > endstring = "TOTL" > > sData = ReadFile("C:\Documents and Settings\Owner.AJAYGARG\My > Documents\ASSOCIATION TOTALS BY ACCOUNT TYPE.doc") > > > startposition = InStr(sData, startstring) > sData = Left(sData, startposition) > endposition = InStr(sData, endstring) + Len(endstring) - 1 > sData = Left(sData, endposition) > > > WScript.echo sData > > > Function ReadFile(FilePath) > 'Given the path to a file, will return entire contents > ' works with either ANSI or Unicode > Dim FSO, CurrentFile > Const ForReading = 1, TristateUseDefault = -2, _ > DoNotCreateFile = False > Set FSO = createobject("Scripting.FileSystemObject") > If FSO.FileExists(FilePath) Then > If FSO.GetFile(FilePath).Size>0 Then > Set CurrentFile = FSO.OpenTextFile(FilePath, ForReading, _ > False, TristateUseDefault) > If CurrentFile.AtEndOfStream <> True Then > ReadFile = CurrentFile.ReadAll > WriteFile "C:\Documents and Settings\Owner.AJAYGARG\My > Documents\ASSOCIATION TOTALS BY ACCOUNT TYPEf.doc", outData > : CurrentFile.Close > End If > End If > End If > End Function > > Sub WriteFile(FILEPATH, sData) > 'writes sData to FilePath > With CreateObject("Scripting.FileSystemObject")._ > OpenTextFile(FilePath, 2, True) > .Write sData: .Close > End With > End Sub > |
|||||||||||||||||||||||