Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 118
  • Last Modified:

Need sourcecode for vb-script...

Hi!

Have a textfile that i need a vb-script file to do this:

Read textfile and find the text "Hittil" , when the text "Hittil" in the textfile is found.
It must insert needed blank lines befor "Hittil"....

Example textfile:

This is line 1
This is line 2
This is line 3
This is line 4
This is line 5
This is line 6
This is line 7 Hittil

Example textfile 2:

This is line 1
This is line 2
This is line 3
This is line 4
This is line 5 Hittil

Wanted result for tekstfile 2:
This is line 1
This is line 2
This is line 3
This is line 4


This is line 5 Hittil


So the script must count number of lines before it find "Hittil", and the insert needed blank lines.

Can please sombody give me the source for this vb-script ?

THANKS

Tor
0
team2005
Asked:
team2005
1 Solution
 
vinnyd79Commented:
Something like this?

Dim fso,fil,Line,fData
Set fso = CreateObject("Scripting.FileSystemObject")
Set fil = fso.OpenTextFile("C:\Test.txt",1)
While Not fil.AtEndOfStream
   Line = fil.ReadLine
   if Instr(Line,"Hittil") Then
      fData = fData & vbCrLf & vbCrLf  & vbCrLf & Line
   Else
      if fData = "" Then
            fData = Line
         Else
            fData = fData & vbcrlf & Line
         End if
   End if
Wend
fil.Close
Set fil = fso.OpenTextFile("C:\Test.txt",2)
fil.Write fData
fil.close
Set fil = Nothing
Set fso = Nothing
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now