设计vbs程序,让他挨个输出1到1000内所有数字,并每输出一个数字就按一下下键

设计vbs程序,让他挨个输出1到1000内所有数字,并每输出一个数字就按一下下键,第1张

下面代码保存为xxx.vbs文件。由于gui不易实现连续显示,所以使察宴用命慧简令行窗口显示。每0.1秒按下一个键

###########################################

If (Lcase(Right(Wscript.FullName,11)) = "wscript.exe") Then

CreateObject("WScript.Shell").Run("%Comspec% /C ""Title 按数字键 &&Cscript.exe //NoLogo """ &Wscript.ScriptFullName &"""""前没裤"), 3

Wscript.Quit

End If

Set fso = CreateObject("Scripting.FileSystemObject")

Set ws = wscript.createobject("wscript.shell")

wscript.sleep 3000

for i = 1 to 1000

ws.sendkeys i

wscript.echo i

wscript.sleep 100

next

这东西很麻烦。蔽缓我代码虽然已经写好了,宏睁模但有点错误,不知道怎么改了。

首先创建一个【主程序.vbs】,代码如下:

Dim MainContainer, Window, Document

Set MainContainer = CreateObject("InternetExplorer.Application")

MainContainer.Navigate "about:blank"

MainContainer.Visible = True

Set Window = MainContainer.Document.parentWindow

Set Document = Window.document

Dim TextBox1

Set TextBox1 = Document.CreateElement("<input type='text' id='TextBox1'>")

Document.body.appendChild TextBox1

dim a,b,c

a=inputbox("请输入开始快捷键(F0~F9)")

b=inputbox("请输入结束快捷键(F0~F9)")

c=inputbox("请输入循环时间(秒)")

dim fso,w

Set fso = CreateObject("Scripting.FileSystemObject")

Set w=fso.OpenTextFile ("临时.txt",2,1)

w.Write ( a &vbcrlf &b)

w.Close

dim ws

set ws = createobject("wscript.shell")

ws.run "开始.vbs"

ws.run "结早皮束.vbs"

i=c

do while ss

ss = fso.fileExists(strFilePath)

i=i-1

textbox1.value=i

j=j+1

if j=30 then ss=true

wscript.sleep 1000

loop

msgbox "程序结束"

textbox1.value="程序结束"

ws.DeleteFile("临时.txt"), True

ws.run "taskkill /im WScript.exe /f"

再创建一个【开始.vbs】,代码如下:

Dim strDllPath

strDllPath = Replace(WScript.ScriptFullName,WScript.ScriptName,"dynwrap.dll") '获取DLL文件的绝对路径

RegisterCOM strDllPath '注册DynamicWrapper组件

Dim g_objConnectAPI

Set g_objConnectAPI = CreateObject("DynamicWrapper") '创建全局的DynamicWrapper组件对象实例

'以下为声明将要用到的Win32API函数

With g_objConnectAPI

.Register "user32.dll","GetAsyncKeyState","i=l","f=s","r=l"

End With

dim b,fso

Set fso = CreateObject("scripting.filesystemobject")

Set X=fso.OpenTextFile("临时.txt",1)

a="[" &X.ReadLine &"]"

do until thekey=a

thekey=GetThePressKey()

wscript.sleep 1

loop

Set fso = CreateObject("Scripting.FileSystemObject")

Set w=fso.OpenTextFile ("运行.txt",2,1)

w.Write ("")

w.Close

还有【结束.vbs】,代码如下:

Dim strDllPath

strDllPath = Replace(WScript.ScriptFullName,WScript.ScriptName,"dynwrap.dll") '获取DLL文件的绝对路径

RegisterCOM strDllPath '注册DynamicWrapper组件

Dim g_objConnectAPI

Set g_objConnectAPI = CreateObject("DynamicWrapper") '创建全局的DynamicWrapper组件对象实例

'以下为声明将要用到的Win32API函数

With g_objConnectAPI

.Register "user32.dll","GetAsyncKeyState","i=l","f=s","r=l"

End With

dim b,fso

Set fso = CreateObject("scripting.filesystemobject")

Set X=fso.OpenTextFile("临时.txt",1)

X.ReadLine

b="[" &X.ReadLine &"]"

do until thekey=b

thekey=GetThePressKey()

wscript.sleep 1

loop

CreateObject("Scripting.FileSystemObject").DeleteFile("运行.txt"), True

这三个文件缺一不可,是互相配合的。

主程序.vbs正常,开始.vbs和结束.vbs出错。不知道怎么改了。你可以把这两个VBS的代码发在百度上提问。

dim strMTH,strDY,strWK,strDT

if len(month(now))=1 then

strMTH="0" &month(now)

else

strMTH=month(now)

end if

if len(day(now))=1 then

strDY="0" &day(now)

else

strDY=day(now)

end if

if weekday(now)=1 then

strWK = "日"

elseif weekday(Now)=2 then

strWK = "一"

elseif weekday(Now)=3 then

strWK = "二"

elseif weekday(Now)=4 then

strWK = "三"

elseif weekday(Now)=5 then

strWK = "四"

elseif weekday(Now)=6 then

strWK = "五"

elseif weekday(Now)=7 then

strWK = "旦州六"

end if

strDT=year(Now) &"年" &strMTH &"月" &strDY &"日星期" &strWK

把strDT放到模旅蔽你镇肢想要的地方就行了


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12404579.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存