Home All Groups Group Topic Archive Search About

How can i output data between 2 strings to another file

Author
3 Feb 2006 10:53 PM
AG
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

Author
4 Feb 2006 5:25 PM
Veign
Show your code....

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
Veign's Blog
http://www.veign.com/blog
--


Show quoteHide quote
"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
>
Author
4 Feb 2006 6:51 PM
AG
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
Author
4 Feb 2006 8:00 PM
Veign
VBS is not VB so you would be better off posting in the scripting newsgroup.

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
Veign's Blog
http://www.veign.com/blog
--


Show quoteHide quote
"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
>