2009-05-20 4 views
2

이 스크립트가 두 개 값을 하나가 아닌 동일한 텍스트 파일로 대체하려고합니다. 그러나 12 행의 주석 처리를 제거하면 스크립트가 중단됩니다. 이것을 루프로 만들어야합니까, 아니면 여러 번 대체 할 수 있습니까? 첫 번째 교체vbscript 대체 텍스트 - 하나가 두 개 모두 작동합니다.

strNewText = Replace(strText, "***COMPNAME***", strCompname) 
strNewText = Replace(strNewText , "***Winkey***", strPoductkey) 

그렇지 않으면 당신은 잃게됩니다, 단지 두 번째가 나타납니다 :

Sub ReplaceTxt() 
'Writes values we got earlier to our unattend file  ' 
Const ForReading = 1 
Const ForWriting = 2 

    Set objFSO = CreateObject("Scripting.FileSystemObject") 
    Set objFile = objFSO.OpenTextFile(strSIFpath, ForReading) 

    strText = objFile.ReadAll 
    objFile.Close 
    strNewText = Replace(strText, "***COMPNAME***", strCompname) 
' strNewText = Replace(strText, "***Winkey***", strPoductkey) ' 

    Set objFile = objFSO.OpenTextFile("C:\$WIN_NT$.~BT\winnt.sif", ForWriting) 
    objFile.WriteLine strNewText 
    objFile.Close 
End Sub 
+0

당신은 각 교체품을 인쇄하고 싶다고 분명히 밝혀야합니다. 그렇지 않으면 Frederik의 코드가 동시에 교체 한 다음 인쇄하려는 경우에 효과적입니다. – Malachi

답변

6

나는 당신이 두 번째 첫 번째에 의해 반환 된 문자열 교체를하고 싶은 생각 결과.

0

이 시도 :

Sub ReplaceTxt() 'Writes values we got earlier to our unattend file' 
    Const ForReading = 1 
    Const ForWriting = 2 

    Set objFSO = CreateObject("Scripting.FileSystemObject") 
    Set objFile = objFSO.OpenTextFile(strSIFpath, ForReading) 

    strText = objFile.ReadAll 
    objFile.Close 

    strText = Replace(strText, "COMPNAME", strCompname) 
    strText = Replace(strText, "Winkey", strPoductkey) 

    Set objFile = objFSO.OpenTextFile("C:\$WIN_NT$.~BT\winnt.sif", ForWriting) 
    objFile.WriteLine strText 
    objFile.Close 
End Sub 

그것은 당신이했던 방법을함으로써, 당신은 당신이 두 번째 한 때 먼저 교체 덮어 두 번 원래 사용되지 않는 텍스트를 사용했다.

+0

objFile.WriteLine strNewText는 strText이어야합니다. – AnthonyWJones

+0

감사합니다. 커피가 부족합니다. : D – AnonJr

+0

둘 다 똑같은 일을하고, 먼저 작품을 대체하고, 두 번째는 비어 있습니다. – Travis

0

나는 나의 문 .. 거기 진짜 코더에 추한이지만, 여기에 내가 잘

Sub ReplaceTxt() 'Writes values we got earlier to our unattend file' 
    Const ForReading = 1 
    Const ForWriting = 2 
    counter = 1 

    For Each searchterm In Array("COMPNAME", "Winkey") 
     Set objFSO = CreateObject("Scripting.FileSystemObject") 
     Set objFile = objFSO.OpenTextFile(strSIFpath, ForReading) 

     strText = objFile.ReadAll 
     objFile.Close 

     If counter < 2 Then 
     strText = Replace(strText, searchterm, strCompname) 
     Else 
     strText = Replace(strText, searchterm, strProductKey) 
     End If 

     Set objFile = objFSO.OpenTextFile("C:\$WIN_NT$.~BT\winnt.sif", ForWriting) 
     objFile.WriteLine strText 
     objFile.Close 
     counter = counter + 1 
    Next 
End Sub 
0

를 작동하는 데있어 얼마나 있는지 쉽게 .. 흠 NI 담당 .. 난 그게 전부를하려고했던거야 이 일을하는 것이 좋습니다. 나는 대답을 찾았다 :

Sub ReplaceTxt() 
'Writes values we got earlier to our unattend file  ' 
Const ForReading = 1 
Const ForWriting = 2 

Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objFile = objFSO.OpenTextFile(strSIFpath, ForReading) 

strText = objFile.ReadAll 
objFile.Close 
strNewText = Replace(strText, "***COMPNAME***", strCompname) 
strNewText2 = Replace(strNewText, "***Winkey***", strPoductkey) ' 

Set objFile = objFSO.OpenTextFile("C:\$WIN_NT$.~BT\winnt.sif", ForWriting) 
objFile.WriteLine strNewText2 
objFile.Close 
End Sub 

탱크, Gracias. José Villa Culiacán, Sinaloa Mexico

관련 문제