找回密码
 加入
搜索
查看: 2967|回复: 3

[AU3基础] 【已解决】关于数组取值的一个问题,运行前不提示错误,运行后提示

[复制链接]
发表于 2013-5-24 11:13:16 | 显示全部楼层 |阅读模式
本帖最后由 cynthia59 于 2013-5-24 13:24 编辑

读取数组里的值,运行前不提示错误,能弹出框,但运行结束会提示有错误。
当RunPressed中有多个条件语句时只能运行第一个,不知是否与这个错误提示有关系?
请高手帮忙看一下?
#include <GuiConstantsEx.au3>
#include <ButtonConstants.au3>
#include <Constants.au3>
#include <EditConstants.au3>

Opt ('GUIOnEventMode',1)

; GUI
$parent = GuiCreate('1', 400, 420)
GUISetOnEvent($GUI_EVENT_CLOSE, 'SpecialEvents')
GUISetOnEvent($GUI_EVENT_MINIMIZE, 'SpecialEvents')
GUISetOnEvent($GUI_EVENT_RESTORE, 'SpecialEvents')

$Edit_1 = GuiCtrlCreateEdit('1'& @CRLF & '2' & @CRLF &'3' & @CRLF, 10, 93, 380, 150 )


$Button_8 = GuiCtrlCreateButton('运行脚本', 250, 383 , 143 , 30)
    GUICtrlSetOnEvent(-1, 'RunPressed')        

Func RunPressed()
        
        $str = GUICtrlRead($Edit_1)                                                ;获取工程列表
        If StringRight($Str, 1) = @LF Then $Str = StringTrimRight($Str, 1)                                ;去掉最后一个空行
        $ProjName = StringSplit ( $str, @LF , 1 )                ;读取工程列表,拆分成数组返回
                
                For $i=1 to UBound($ProjName)

                        If Not @Error Then _Cal($ProjName[$i])                        ;这句提示错误!!!!!!!!!

                Next
EndFunc


Func _Cal($ProjName)
        MsgBox(0,'',$ProjName)
EndFunc

Func SpecialEvents()
        Select
                Case @GUI_CtrlId = $GUI_EVENT_CLOSE
                        Exit

                Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE

                Case @GUI_CtrlId = $GUI_EVENT_RESTORE

        EndSelect
EndFunc   ;==>SpecialEvents

; GUI MESSAGE LOOP
GuiSetState()
While GuiGetMsg() <> $GUI_EVENT_CLOSE
WEnd
发表于 2013-5-24 11:36:27 | 显示全部楼层
        $ProjName = StringSplit($str, @LF, 1) ;读取工程列表,拆分成数组返回
        If @error Then Return
        For $i = 1 To $ProjName[0]
                _Cal($ProjName[$i]) ;这句提示错误!!!!!!!!!
        Next
 楼主| 发表于 2013-5-24 13:24:05 | 显示全部楼层
我知道我错哪了,又仔细看了下帮助文档发现"UBound 返回的数值比数组最后一个元素的下标大1"这句,原来是每次读到最后一个读不到所以错了,在 UBound($ProjName) 后面加上 -1 就对了。
不过afan大哥给的方式更简单些,还帮我补充了一个遇错返回的,谢谢啦!
发表于 2013-8-4 19:21:29 | 显示全部楼层
好好好好好好好好好好好好好好好好好好
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-28 23:32 , Processed in 0.148046 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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