gpt4 book ai didi

VBScript 脚本进度通知

转载 作者:行者123 更新时间:2023-12-04 01:56:59 26 4
gpt4 key购买 nike

我是 VBScript 新手,正在编写一个脚本来解析大型输入文件,并且可能需要几分钟的运行时间来完成处理。我需要一种方法来提醒用户脚本在这么长的处理时间内运行没有错误。我的第一个想法是为处理的每 1000 条记录显示一个 msgbox(例如“到目前为止脚本已成功处理了 1000 条记录。”)还没有完全破解编码增量器的正确方法,该增量器将有条件地每第 N 条记录触发一个 msgbox(或确定是否有更好的方法来实现我的最终目标)。有任何想法吗?

最佳答案

如果您在控制台窗口中运行脚本(通过 cscript.exe),那么您可以直接在窗口/输出中显示一个人造进度条,如下所示:

console window progress bar

首先在 VBS 文件中声明以下函数:

Function printi(txt)
WScript.StdOut.Write txt
End Function

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

然后在脚本的顶部使用以下示例:
ForceConsole()

For i = 1 To 100
progress(i, 100)
Next

关于VBScript 脚本进度通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18216027/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com