找回密码
 加入
搜索
查看: 637|回复: 4

[AU3基础] exitloop

[复制链接]
发表于 2022-12-16 13:57:22 | 显示全部楼层 |阅读模式
新手發問,想問高手我在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

发表于 2022-12-16 16:22:30 | 显示全部楼层
#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
发表于 2022-12-19 07:44:23 | 显示全部楼层
sleep 时间太久,Windows窗口消息阻塞了,影响了后面的点击控件

可以用 AdlibRegister 注册一个定时函数,定时执行你的任务

还可以用 Timerini 记录时间点,然后在主循环里检测时间,到点就执行你的定时任务

这2种方法,都需要预设2个全局变量,1个存储执行的任务的次数,另一个存储终止状态,就能控制执行次数及终止任务的执行了
 楼主| 发表于 2022-12-19 08:35:20 | 显示全部楼层
3131210 发表于 2022-12-16 16:22
#include
#include
#include

謝謝,修改一下可以達成了!!!!
 楼主| 发表于 2022-12-19 08:35:46 | 显示全部楼层
user3000 发表于 2022-12-19 07:44
sleep 时间太久,Windows窗口消息阻塞了,影响了后面的点击控件

可以用 AdlibRegister 注册一个定时函数 ...

感謝建議!!!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-29 23:12 , Processed in 0.068541 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表