Loops 输入循环变得不同步
因此,我尝试制作一个自动热键输入脚本,以便在工作中自动执行非常繁琐的数据输入。基本上,我已经设置好了它,这样它就可以通过复制和粘贴将Excel电子表格中的数据拉到我们的数据库程序中,还可以手动输入一些保持不变的内容 它要求用户输入要输入的零件数量,然后循环多次 我的问题是,在流程中循环几次后,它不可避免地会失去同步,然后无法正常继续,必须重新开始 我尝试了一些不同的方法,包括将键延迟设置得更高,并添加了各种睡眠、xxx行,但问题仍然存在Loops 输入循环变得不同步,loops,synchronization,autohotkey,Loops,Synchronization,Autohotkey,因此,我尝试制作一个自动热键输入脚本,以便在工作中自动执行非常繁琐的数据输入。基本上,我已经设置好了它,这样它就可以通过复制和粘贴将Excel电子表格中的数据拉到我们的数据库程序中,还可以手动输入一些保持不变的内容 它要求用户输入要输入的零件数量,然后循环多次 我的问题是,在流程中循环几次后,它不可避免地会失去同步,然后无法正常继续,必须重新开始 我尝试了一些不同的方法,包括将键延迟设置得更高,并添加了各种睡眠、xxx行,但问题仍然存在 setKeyDelay, 60,60 F1:: Gu
setKeyDelay, 60,60
F1::
Gui, Add, Picture, , I:\TPM MAINTENANCE\Robb's BoM Input Macro\BB.PNG
Gui, Add, text, , Enter # of Parts:
Gui, Add, Edit, vNum
Gui, Add, Button, default, OK
Gui, Show
Return
ButtonOK:
Gui, Submit
/*Loop Variables
Counter := 1
Percentage := 100 / Num
Start := 0
Progress, w500,, Adding Parts..., BoM Macro
Loop, %Num%
{
/* Item Category and Unit of Measurement
Send N{TAB}{TAB}{TAB}EA{ENTER}
/* Grabs Quantity from Excel
Winactivate, Microsoft Excel
winwaitactive, Microsoft Excel, , 10
Send ^c
WinActivate, Create material BOM
WinWaitActive, Create material BOM, , 10
Send ^v
Send {ENTER}
/*Grabs Description from Excel
Winactivate, Microsoft Excel
winwaitactive, Microsoft Excel, , 10
Send {RIGHT}
Send ^c
Winactivate, Create material BOM
winwaitactive, Create material BOM, , 10
Send ^v
/*Grabs Manufacturer Part Number from Excel
Winactivate, Microsoft Excel
winwaitactive, Microsoft Excel, , 10
Send {RIGHT}
Send ^c
Winactivate Create material BOM
winwaitactive, Create material BOM, , 10
Send {TAB}{TAB}
Send ^v
Send {ENTER}
/*Entering Purchasing Data
Send .0
Send {TAB}{TAB}
Send G04
Send {TAB}{TAB}
Winactivate, Microsoft Excel
winwaitactive, Microsoft Excel, , 10
Send {RIGHT}
Send ^c
Winactivate, Create material BOM
winwaitactive, Create material BOM, , 10
Send ^v
Send {TAB}{TAB}{TAB}
Send PM002
Send {ENTER}
/*Pointing Excel at the next item
Winactivate, Microsoft Excel
winwaitactive, Microsoft Excel, , 10
Send {LEFT}{LEFT}{LEFT}{DOWN}
Winactivate, Create material BOM
winwaitactive, Create material BOM, , 10
/*Loop to correctly position SAP pointer
Loop, %Counter%
{
Send {DOWN}
}
Send {TAB}
Counter++
Increment := ++start
Result := Percentage * Increment
Progress, %Result%
}
Progress, 100
Sleep, 800
Progress, off
GuiClose:
Gui, Destroy
1.您也可以使用剪贴板变量的内容,而不是在每次复制后在窗口之间切换。这可能会最小化脚本出错的机会。我很想举个例子,但愚蠢的评论部分不让我这么做。2.您还可以访问循环3的内置变量A_Index,而不是Counter。究竟什么变成了去同步?哪里我想您大概知道,因为您的程序似乎自己注意到了这一点1。我不知道剪贴板命令-我将不得不研究它。非常感谢。2.好主意。老实说,这是奇怪的部分。我早在2到3个循环时就已经使用过desync,晚到13个…我希望结合剪贴板变量和一些适时的睡眠命令可以让它冷静下来。有更简单、更可靠的方法来操作Excel工作表。我认为最好的选择是使用。第二个选项是在AHK中使用相应的COM对象。我想知道的不是脚本失步前循环完成的数量,而是脚本在循环中的哪一点中断,如果这是一致的,不管在那一点中断的循环数是多少。