Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writng value to multiple files 1

Status
Not open for further replies.

HVtech

IS-IT--Management
Jul 1, 2010
71
NL
Hi,
I am trying to write a value to three different files, using replace.

Since I'm no coder, I created for every file a different piece of code, probably could be written much cleaner.
Something with a loop or so ? Who can help me with this?

Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
 r="c:\windows\setup\scripts\reboot1.reg"
 Set objTextFile = objFSO.OpenTextFile(r,1)
 s = objtextfile.readall
 n = "####"
 snew = Replace(s,n,BiosAT)
 objTextFile.close
 set objtextfile=nothing
 
 ' delete old file
 ' objfso.DeleteFile r, true
 
 'write new file
 set objTextFile = objfso.CreateTextFile(r)
 objTextFile.Write snew
 objTextFile.Close
 set objTextFile = nothing
 
 
 ' Adjust second file
  Set objFSO = CreateObject("Scripting.FileSystemObject")
 r="c:\windows\setup\scripts\reboot2.reg"
 Set objTextFile = objFSO.OpenTextFile(r,1)
 s = objtextfile.readall
 n = "####"
 snew = Replace(s,n,BiosAT)
 objTextFile.close
 set objtextfile=nothing
 
 ' delete old file
 ' objfso.DeleteFile r, true
 
 'write new file
 set objTextFile = objfso.CreateTextFile(r)
 objTextFile.Write snew
 objTextFile.Close
 set objTextFile = nothing
 
 
  ' Adjust third file
  Set objFSO = CreateObject("Scripting.FileSystemObject")
 r="c:\windows\setup\scripts\reboot3.reg"
 Set objTextFile = objFSO.OpenTextFile(r,1)
 s = objtextfile.readall
 n = "####"
 snew = Replace(s,n,BiosAT)
 objTextFile.close
 set objtextfile=nothing
 
 ' delete old file
 ' objfso.DeleteFile r, true
 
 'write new file
 set objTextFile = objfso.CreateTextFile(r)
 objTextFile.Write snew
 objTextFile.Close
 set objTextFile = nothing
 
Like this ?
Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
For i=1 To 3
 r="c:\windows\setup\scripts\reboot" & i & ".reg"
 Set objTextFile = objFSO.OpenTextFile(r,1)
 s = objtextfile.readall
 n = "####"
 snew = Replace(s,n,BiosAT)
 objTextFile.close
 set objtextfile=nothing
 
 ' delete old file
 ' objfso.DeleteFile r, true
 
 'write new file
 set objTextFile = objfso.CreateTextFile(r)
 objTextFile.Write snew
 objTextFile.Close
 set objTextFile = nothing
Next

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top