2015-08-13 55 views
1

我有一個關於vbs迴路的問題VBS迴路問題

我的腳本正在讀取每行的文件行並執行一些任務。 接下來我把錯誤恢復。

當發生錯誤時,腳本繼續循環BUT與下一個參數(下一行)。 有沒有提示腳本繼續使用相同的參數循環?

這是腳本。

on error resume next 
dim filesys, text, readfile, contents, copy, oNet, objLog 
set filesys = CreateObject("Scripting.FileSystemObject") 
set readfile = filesys.OpenTextFile("xxxx", 1, false) 
set copy = CreateObject("Scripting.FileSystemObject") 
set oNet = CreateObject("Wscript.Network") 
set objLog = filesys.OpenTextFile("xxxx", 8, true) 

do while readfile.AtEndOfStream=false 
objLog.WriteLine "0" 
contents = readfile.ReadLine 
Drive = "Z:" 
User = "xxx" 
Pass = "xxx" 
PER = "FALSE" 
Share = "\\" & contents & "\c$\windows\temp" 
oNet.MapNetworkDrive Drive, Share, PER, User, Pass 
objLog.WriteLine "1" 
If Err.Number <> 0 Then 
objLog.WriteLine "1.1" 
objLog.WriteLine readfile.ReadLine & " ---- ATTENTION: " & Err.Description 
' wscript.echo "ATTENTION: " & Err.Description 
Err.Clear 
End If 
copy.CopyFile "Z:\xxx", "xxx" & contents & ".log" 
objLog.WriteLine "2" 
If Err.Number <> 0 Then 
objLog.WriteLine "2.1" 
objLog.WriteLine readfile.ReadLine & " ---- ATTENTION: " & Err.Description 
' wscript.echo "ATTENTION: " & Err.Description 
Err.Clear 
End If 
objLog.WriteLine "3" 
WScript.Sleep 5000 
oNet.RemoveNetworkDrive "Z:" 
objLog.WriteLine "4" 
loop 
readfile.close 

回答

0

對不起,它似乎工作。

我修改這個對數:

objLog.WriteLine readfile.ReadLine & " ---- ATTENTION: " & Err.Description 

通過

objLog.WriteLine contents & " ---- ATTENTION: " & Err.Description 

現在的日誌是確定的。它繼續。對不起,這個:)

0

在錯誤的情況下,你的

objLog.WriteLine readfile.ReadLine & " ---- ATTENTION: " & Err.Description 

讀取/使用了從源文件中的下一行。使用

objLog.WriteLine contents & " ---- ATTENTION: " & Err.Description 

代替。