找回密码
 加入
搜索
查看: 1632|回复: 7

[AU3基础] 如何用输入框自定脚本循环执行次数?[已解决]

  [复制链接]
发表于 2016-11-21 00:08:56 | 显示全部楼层 |阅读模式
本帖最后由 zhzhtx 于 2016-11-22 21:39 编辑

各位老大:本人新手,想通过输入框来自定义脚本循环执行次数,可是怎么改都不成功,烦请各位老大帮忙修改一下,或者给个思路.
现在情况是不管输入什么数字,都无限循环,并且自己没有什么其它思路了.
脚本如下:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
HotKeySet("{ESC}", "_stop")
$Form1 = GUICreate("提示", 181, 161, 192, 114)
$Label1 = GUICtrlCreateLabel("请输入循环次数:", 24, 24, 91, 17)
$start = GUICtrlCreateButton("开始", 24, 104, 57, 25)
GUICtrlSetOnEvent($start, "_start1")
$stop = GUICtrlCreateButton("停止", 96, 104, 57, 25)
GUICtrlSetOnEvent($stop, "_stop")
$Input1 = GUICtrlCreateInput("", 24, 48, 129, 25, 0x2000)
Dim $Form1_AccelTable[2][2] = [["^{F10}", $start],["^{F12}", $stop]]
GUISetAccelerators($Form1_AccelTable)
GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
        EndSwitch
WEnd

Func _start1()
        $Input=GUICtrlRead($Input1)
        If  $Input="" Then
                MsgBox (0, "提示", "请输入循环执行次数,不能为空")
        ElseIf $Input=0 Then
                MsgBox (0, "提示", "你想干吗????")
        ElseIf $Input>0 Then
                $Input=$Input-1
                _start2()
        EndIf
EndFunc

Func _start2()
        MouseMove (5, 5)
        Sleep(500)
        MouseMove (50, 50)
        Sleep(500)
        _start1()
EndFunc

Func _stop()
    Exit
EndFunc
发表于 2016-11-21 01:02:56 | 显示全部楼层
回复 1# zhzhtx


#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
HotKeySet("{ESC}", "_stop")
$Form1 = GUICreate("提示", 181, 161, 192, 114)
$Label1 = GUICtrlCreateLabel("??入循?次?:", 24, 24, 91, 17)
$start = GUICtrlCreateButton("?始", 24, 104, 57, 25)
GUICtrlSetOnEvent($start, "_start1")
$stop = GUICtrlCreateButton("停止", 96, 104, 57, 25)
GUICtrlSetOnEvent($stop, "_stop")
$Input1 = GUICtrlCreateInput("", 24, 48, 129, 25, 0x2000)
Dim $Form1_AccelTable[2][2] = [["^{F10}", $start],["^{F12}", $stop]]
GUISetAccelerators($Form1_AccelTable)
GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
        EndSwitch
WEnd

Func _start1()
        Global $Input=GUICtrlRead($Input1)
        If  $Input="" Then
                MsgBox (0, "提示", "??入循??行次?,不能?空")
        ElseIf $Input=0 Then
                MsgBox (0, "提示", "你想干?????")
        ElseIf $Input>0 Then
                
                _start2()
        EndIf
EndFunc

Func _start2()
                FOR $1=1 TO $Input 
                        
                        MouseMove (5, 5)
                        Sleep(500)
                        MouseMove (50, 50)
                        Sleep(500)
        Next
EndFunc

Func _stop()
    Exit
EndFunc
 楼主| 发表于 2016-11-21 14:58:03 | 显示全部楼层
回复 2# kk_lee69


感谢帮忙,按照这样改的话只能重复 _start2()里的内容,而实际需求是需要安装一个软件,自动做一些操作后再将其卸载,然后再从头开始安装,卸载……这样重复运行自定义的次数.
不好意思,一楼没讲清楚需求.
发表于 2016-11-21 16:43:42 | 显示全部楼层
回复 3# zhzhtx


    既然你的需求是需要安装一个软件,自动做一些操作后再将其卸载,然后再从头开始安装,卸载……


那就将需求写在_start2()里,不就结了
发表于 2016-11-21 18:15:33 | 显示全部楼层
回复 3# zhzhtx

那就只好 請你 寫出範例了
 楼主| 发表于 2016-11-21 18:21:12 | 显示全部楼层
回复 4# ap112


因为安装,卸载过程中自定义了很多函数,函数里面好像又不能再定义其它函数(不知道是否可以),所以不能将所有代码全部放到_start2()里.
发表于 2016-11-22 08:48:05 | 显示全部楼层
回复 6# zhzhtx


    函数内调用其它函数当然没问题,而且是你想嵌套几个嵌套几个,想嵌套多少层潜逃多少层,递归就是一种调用自己的嵌套。。。。
 楼主| 发表于 2016-11-22 21:39:11 | 显示全部楼层
多谢两位的帮忙和提醒,现在知道该怎么写了。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-26 20:26 , Processed in 0.078803 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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