exitloop
新手發問,想問高手我在case $Button1總共要執行60次指令,但想用$Button2來停止他,為什麼exitloop無反應,謝謝代碼如下
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 254, 323, 664, 210)
$Edit1 = GUICtrlCreateEdit("", 32, 32, 193, 97)
GUICtrlSetData(-1, "show logging error重覆60次" & @CRLF & "總時1h1分鐘1次")
$Button1 = GUICtrlCreateButton("logging error", 40, 144, 139, 57)
$Button2 = GUICtrlCreateButton("stop", 40, 224, 139, 57)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
WinWaitActive("COM5:9600baud - Tera Term VT")
sleep(500)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
send("show logging error")
Send("{ENTER}")
sleep(60000)
Send("{ENTER}")
Send("{ENTER}")
if $Button2 then ExitLoop
EndSwitch
WEnd
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 254, 323, 664, 210)
$Edit1 = GUICtrlCreateEdit("", 32, 32, 193, 97)
GUICtrlSetData(-1, "show logging error重覆60次" & @CRLF & "總時1h1分鐘1次")
$Button1 = GUICtrlCreateButton("logging error", 40, 144, 139, 57)
$Button2 = GUICtrlCreateButton("stop", 40, 224, 139, 57)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
Global $ts = 0
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$ts = 1
For $i = 1 To 60
If $ts = 0 Then
ExitLoop
Else
GUICtrlSetData($Edit1, "show logging error " & $i)
Sleep(1000)
EndIf
Next
EndSwitch
WEnd
Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
#forceref $hWnd, $msg
Local $nNotifyCode = BitShift($wParam, 16)
Local $nID = BitAND($wParam, 0x0000FFFF)
Local $hCtrl = $lParam
Switch $hCtrl
Case GUICtrlGetHandle($Button2)
$ts = 0
EndSwitch
EndFunc ;==>WM_COMMAND
sleep 时间太久,Windows窗口消息阻塞了,影响了后面的点击控件
可以用 AdlibRegister 注册一个定时函数,定时执行你的任务
还可以用 Timerini 记录时间点,然后在主循环里检测时间,到点就执行你的定时任务
这2种方法,都需要预设2个全局变量,1个存储执行的任务的次数,另一个存储终止状态,就能控制执行次数及终止任务的执行了
3131210 发表于 2022-12-16 16:22
#include
#include
#include
謝謝,修改一下可以達成了!!!! user3000 发表于 2022-12-19 07:44
sleep 时间太久,Windows窗口消息阻塞了,影响了后面的点击控件
可以用 AdlibRegister 注册一个定时函数 ...
感謝建議!!!
页:
[1]