2013-08-13 82 views
7

私はVBScriptの初心者です。大きな入力ファイルを解析するスクリプトを作成し、処理を完了するまでに数分の実行時間がかかることがあります。この長い処理時間中にスクリプトがエラーなく実行されていることをユーザーに警告する方法が必要です。私の最初の考えは、処理された1000番目のレコードごとにmsgboxを表示することでした(例えば、 "スクリプトはこれまで1000レコードを正常に処理しました")。私の最終目標を達成するためのより良い方法があるかどうかを判断する)。何か案は?VBScriptスクリプトの進捗状況の通知

答えて

2

この場合、WshShell.Popupメソッドを使用して現在の進捗状況に関する情報を提供したいと考えています。ここで

例:あなたはあなたのユーザーのうちの一体を困らせるために必要がない限り、

Dim WshShell, i 
Set WshShell = CreateObject("WScript.Shell") 

For i = 1 To 500 
    'Do Something 
    If i Mod 100 = 0 Then 'inform for every 100 process 
     WshShell.Popup i & " items processed", 1, "Progress" ' show message box for a second and close 
    End If 
Next 
4

はこのためにポップアップメッセージを使用しないでください。例えば、this page内の1つのような進行状況インジケータを表示しHTAでコードをラップ:

<html> 
<head> 
<title>Sample</title> 
<hta:application 
    applicationname="Sample" 
    scroll="no" 
    singleinstance="yes" 
    windowstate="normal" 
> 

<script language="vbscript"> 
Sub Window_onLoad 
    'your code here 
End Sub 
</script> 

<style type="text/css"> 
* { 
    font-size: 1px; 
    margin: 1px; 
} 
div { 
    position: absolute; 
    left: 40%; 
    top: 50%; 
} 
marquee { 
    border: 1px solid; 
    height: 15px; 
    width: 200px; 
} 
marquee span { 
    height: 11px; 
    width: 8px; 
    background: Highlight; 
    float: left; 
} 
.handle-0 { filter: alpha(opacity=20); -moz-opacity: 0.20; } 
.handle-1 { filter: alpha(opacity=40); -moz-opacity: 0.40; } 
.handle-2 { filter: alpha(opacity=60); -moz-opacity: 0.6; } 
.handle-3 { filter: alpha(opacity=80); -moz-opacity: 0.8; } 
.handle-4 { filter: alpha(opacity=100); -moz-opacity: 1; } 
</style> 
</head> 

<body> 
<div> 
<marquee direction="right" scrollamount="8" scrolldelay="100"> 
    <span class="handle-0"></span> 
    <span class="handle-1"></span> 
    <span class="handle-2"></span> 
    <span class="handle-3"></span> 
    <span class="handle-4"></span> 
</marquee> 
</div> 
</body> 
</html> 

あなたには、いくつかのより多くの動的な情報を提供したい場合は、例えば、本体にこのような段落を追加することができます。

</div> 
<p id="sline" style="visibility:hidden;">Processed 
<span id="rcount"></span>&nbsp;Records.</p> 
</body> 
</html> 

し、それを更新し、すべての1000の記録:

... 
If numRows Mod 1000 = 0 Then 
    If sline.style.visibility = "hidden" Then sline.style.visibility = "visible" 
    rcount.innerText = numRows 
End If 
... 
5

あなたは(します。cscript.exeを経由して)コンソールウィンドウでスクリプトを実行している場合あなたは、このようなウィンドウ/出力に直接フェイクプログレスバーを表示することができます。あなたのスクリプトの先頭に続いて

Function printr(txt) 
    back(Len(txt)) 
    printi txt 
End Function 

Function back(n) 
    Dim i 
    For i = 1 To n 
     printi chr(08) 
    Next 
End Function 

Function percent(x, y, d) 
    percent = FormatNumber((x/y) * 100, d) & "%" 
End Function 

Function progress(x, y) 
    Dim intLen, strPer, intPer, intProg, intCont 
    intLen = 22 
    strPer = percent(x, y, 1) 
    intPer = FormatNumber(Replace(strPer, "%", ""), 0) 
    intProg = intLen * (intPer/100) 
    intCont = intLen - intProg 
    printr String(intProg, ChrW(9608)) & String(intCont, ChrW(9618)) & " " & strPer 
End Function 

Function ForceConsole() 
    Set oWSH = CreateObject("WScript.Shell") 
    vbsInterpreter = "cscript.exe" 

    If InStr(LCase(WScript.FullName), vbsInterpreter) = 0 Then 
     oWSH.Run vbsInterpreter & " //NoLogo " & Chr(34) & WScript.ScriptFullName & Chr(34) 
     WScript.Quit 
    End If 
End Function 

console window progress bar

まず自分のVBSファイルに次の関数を宣言します次の例を使用してください:

ForceConsole() 

For i = 1 To 100 
    progress(i, 100) 
Next 
関連する問題