找回密码
 加入
搜索
查看: 3914|回复: 8

[AU3基础] [已解决]如何输入数字0进入无限循环

  [复制链接]
发表于 2011-4-19 22:21:55 | 显示全部楼层 |阅读模式
本帖最后由 731106 于 2011-4-19 23:12 编辑

输入一个数字,如果为正整数,就循环几次,如果为0,就进入无限循环,为0进入无限循环应该怎么写?
#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("test", 247, 158)
$Label2 = GUICtrlCreateLabel("数字:", 24, 56, 31, 17)
$Password = GUICtrlCreateInput("", 72, 54, 169, 21, $ES_NUMBER)
GUICtrlSetState(-1, $GUI_FOCUS)
$Button1 = GUICtrlCreateButton("确定", 80, 112, 89, 33)
GUISetState(@SW_SHOW)

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

                Case $Password
                        GUICtrlSetState($Button1, $GUI_FOCUS)
                Case $Button1
                        $gs = GUICtrlRead($Password)
                        ExitLoop
        EndSwitch
WEnd

For $i = 1 To $gs
        MsgBox(0, "Date", $gs)
Next
发表于 2011-4-19 22:35:00 | 显示全部楼层
加个判断就行了吧!
GUICreate('Test', 250, 180)
$Input1 = GUICtrlCreateInput('', 50, 50, 100, 21, 0x2000)
$Button1 = GUICtrlCreateButton('确定', 150, 48, 50, 25)
GUISetState()

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                Case $Button1
                        $iNumber = GUICtrlRead($Input1)
                        If $iNumber = 0 Then
                                While 1
                                        MsgBox(0, '', '无限循环')
                                WEnd
                        Else
                                For $i = 1 To $iNumber
                                        MsgBox(0, '', $i)
                                Next
                        EndIf        
        EndSwitch
WEnd
发表于 2011-4-19 22:42:22 | 显示全部楼层
加个判断不就可以了?这种要求,一般不要用for,用while或do..Until都可以。
发表于 2011-4-19 22:49:50 | 显示全部楼层

$iNum = Number(GUICtrlRead($Password))
For $i = 1 To $iNum + Number($iNum = 0) Step Number($iNum <> 0)
        MsgBox(0, "", $i)
Next

评分

参与人数 1金钱 +30 收起 理由
水木子 + 30 厉害!学习啦!

查看全部评分

 楼主| 发表于 2011-4-19 22:52:57 | 显示全部楼层
加个判断就行了吧!
水木子 发表于 2011-4-19 22:35


这样加判断可是可以,但是如果我判断以后的代码很长的话,那就会造成代码重复太多了,也就是说,IF之后的内容和ELSE之后的内容如果很多的话,而且又是一样,那就重复太多了,有没有更好的办法啊?谢谢
 楼主| 发表于 2011-4-19 22:57:04 | 显示全部楼层
pusofalse 发表于 2011-4-19 22:49


这个太厉害了,就这种办法了,还没回好水木的,就又跳出个高手,万分感谢
发表于 2011-4-19 23:01:15 | 显示全部楼层
是啊!P版很强哦,向他学习吧!
发表于 2011-4-19 23:26:21 | 显示全部楼层
瞻仰P版,有种跳出三界外,不在五行中的意思
发表于 2011-5-22 01:28:53 | 显示全部楼层
不错呀 很好
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-28 04:19 , Processed in 0.128073 second(s), 27 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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