title: VBS replace and write
body: <p>Start of that I'm not that good with VBS but trying to learn.
  Right now I have some difficulties with writing replace to a text file.</p>
  
  <p>What I want to do is to search for the text "VGML", when this is found check on same row if there is a "STML" if so, this should replaced with "    " to not mess up the positions in the file. And finally, if "VGML" is found without the "STML", the "VGML" should be removed.</p>
  
  <p>I got so far when using echo I can see that the code does what I want, but writing to file mostly get me a empty file where the code removed everything.</p>
  
  <p>Could anyone put me in the correct direction?</p>
  
  <p>Here is the code:</p>
  
  <pre><code>Const ForReading = 1
  Const ForWriting = 2
  
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objFile = objFSO.OpenTextFile("C:\Script\RemoveSTML\testFiles\test.txt", ForReading)
  
  strEMTY = "    "
  strSTML = "STML"
  strVGML = "VGML"
  
  Do Until objFile.AtEndOfStream
     strLine = objFile.ReadLine
     If InStr(strLine,strVGML)&gt;0 Then
        If Instr(strLine,strSTML)&gt;0 Then
           strLine = Replace(strLine, strSTML, strEMTY)
           wscript.Echo strLine
        Else
           strLine = Replace(strLine, strVGML, strEMTY)
           wscript.Echo strLine
        End If
     End If                                             
  Loop
  objFile.Close
  Set objFile = objFSO.OpenTextFile("C:\Script\RemoveSTML\testFiles\test.txt", ForWriting)
  objFile.Write strLine
  objFile.Close
  Wscript.Echo "done"
  </code></pre>
  
  <p>Thanks for your help! For giving me a kick in the correct direction!</p>