Need sourcecode for vb-script...

Posted on 2006-04-03
Last Modified: 2012-05-05

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 ?


Question by:team2005
    1 Comment
    LVL 28

    Accepted Solution

    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
          if fData = "" Then
                fData = Line
                fData = fData & vbcrlf & Line
             End if
       End if
    Set fil = fso.OpenTextFile("C:\Test.txt",2)
    fil.Write fData
    Set fil = Nothing
    Set fso = Nothing

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now