找回密码
 加入
搜索
查看: 3871|回复: 16

[AU3基础] Au3的Switch与Select等。[已解决]

 火.. [复制链接]
发表于 2016-9-29 12:34:01 | 显示全部楼层 |阅读模式
本帖最后由 cashiba 于 2017-3-18 09:41 编辑
#include <MsgBoxConstants.au3>

Local $sMsg = ""

Switch @HOUR
    Case 6 To 11
        $sMsg = "早上好"
    Case 12 To 17
        $sMsg = "下午好"
    Case 18 To 21
        $sMsg = "晚上好"
    Case Else
        $sMsg = "你还在干什么?"
EndSwitch
MsgBox($MB_SYSTEMMODAL, "", $sMsg)
一个表达式,用Switch
#include <MsgBoxConstants.au3>
Example()
Func Example()
    Local $iValue = 0
    Local $sBlank = "测试"

    Select
        Case $iValue = 1
            MsgBox($MB_SYSTEMMODAL, "", "第一个表达式为 True.")
        Case $sBlank = "测试"
            MsgBox($MB_SYSTEMMODAL, "", "第二个表达式为 True")
        Case Else ; 如果没有匹配, 则执行以下代码.
            MsgBox($MB_SYSTEMMODAL, "", "前面的表达式都不为 True.")
    EndSelect
EndFunc
多个表达式,用Select。

以前接触的其它语言的,只有select....case....循环或Choose...case....循环。Au3的这种循环复杂些。

另外,do循环,AU3只有一种形式:Do....until
其它语言呢,有
do...loop until
do until...loop
do while....loop
do.....loop while

学多了感觉有点麻爪.
发表于 2016-9-29 13:25:34 | 显示全部楼层
Do....until   循环一直都没用到过。  其他都是看情况使用,select ....endselect 用的多
发表于 2016-9-29 13:28:59 | 显示全部楼层
本帖最后由 heroxianf 于 2016-9-29 13:31 编辑

我一直等着这个东西完成了,再来请教大家给我优化一下,总感觉逻辑厉害的  几行就可以搞定


For $Row = 0 To UBound($ProdArray, 2) - 2
        $oConditions[0] = UBound(StringRegExp($ProdArray[3][$Row + 1], $oExp[0], 3))
        $oConditions[1] = UBound(StringRegExp($ProdArray[3][$Row + 1], $oExp[1], 3))
        $oConditions[2] = UBound(StringRegExp($ProdArray[3][$Row + 1], $oExp[2], 3))

        Select

                Case $oConditions[0] > 0 and $oConditions[1] > 0 and $oConditions[2] > 0

                        _Excel_RangeWrite($oWorkbook, Default, '业务', 'E' & $Row + 2)

                Case $oConditions[0] > 0 and $oConditions[1] > 0 and $oConditions[2] = 0

                        _Excel_RangeWrite($oWorkbook, Default, '业务', 'E' & $Row + 2)

                Case $oConditions[0] > 0 and $oConditions[1] = 0 and $oConditions[2] > 0

                        _Excel_RangeWrite($oWorkbook, Default, '业务', 'E' & $Row + 2)

                Case $oConditions[0] > 0 and $oConditions[1] = 0 and $oConditions[2] = 0

                        _Excel_RangeWrite($oWorkbook, Default, '业务', 'E' & $Row + 2)

                Case $oConditions[0] = 0 and $oConditions[1] > 0 and $oConditions[2] > 0

                        _Excel_RangeWrite($oWorkbook, Default, '业务', 'E' & $Row + 2)

                Case $oConditions[0] = 0 and $oConditions[1] > 0 and $oConditions[2] = 0

                        _Excel_RangeWrite($oWorkbook, Default, '业务', 'E' & $Row + 2)

                Case $oConditions[0] = 0 and $oConditions[1] = 0 and $oConditions[2] > 0

                        _Excel_RangeWrite($oWorkbook, Default, '1', 'E' & $Row + 2)

                Case $oConditions[0] = 0 and $oConditions[1] = 0 and $oConditions[2] = 0

                        _Excel_RangeWrite($oWorkbook, Default, 'Other', 'E' & $Row + 2)

        EndSelect
        Sleep(10)
;        MsgBox(0, $Row + 1, $oConditions[0] & '-' & $oConditions[1] & '-' & $oConditions[2] & '-' & $ProdArray[3][$Row + 1], 1)
Next
发表于 2016-10-4 09:17:57 | 显示全部楼层
学习了  谢谢分享
发表于 2016-10-6 09:29:39 | 显示全部楼层
回复 3# heroxianf


    问一下UBound 这个返回的应该没有负数吧,好像只有三种情况吧  0 0 0;0 0 >0;other
发表于 2016-10-6 11:17:04 | 显示全部楼层
回复 5# 1361739590


    这个问题还没遇到过!
发表于 2016-10-6 11:28:14 | 显示全部楼层
回复 6# heroxianf


    三种情况为什么写那么多case
发表于 2016-10-6 14:47:44 | 显示全部楼层
回复 7# 1361739590


    我是按照主谓宾来判断的。
发表于 2016-10-6 15:45:37 | 显示全部楼层
回复 8# heroxianf


    写成3个不是好看一点么?
发表于 2016-10-6 20:06:23 | 显示全部楼层
回复 9# 1361739590


    写三个貌似不能满足要求,到时候发整个代码还请指点。
发表于 2016-10-7 07:34:31 | 显示全部楼层
回复 10# heroxianf


    按照你上面写的可以分3个,其他情况就具体看了。
发表于 2016-10-13 02:08:49 | 显示全部楼层
这两个各有千秋,使用时要看实际情况
switch 重点是对指定的值进行判断
select 重点是对表达式进行判断
循环的主要是 先循环还是先判断
 楼主| 发表于 2016-10-14 16:01:04 | 显示全部楼层
这两个各有千秋,使用时要看实际情况
switch 重点是对指定的值进行判断
select 重点是对表达式进行判断
...
cihron 发表于 2016-10-13 02:08

AU3的语法主要是参照哪种语言来的呢?感觉不少编程语言,比喻VB等,好像也就只有一种形式就够了
发表于 2016-10-17 02:52:07 | 显示全部楼层
回复 13# cashiba


    何必纠结呢,选择一种自己最喜欢的式,其它的可以忽略。重要的是算法,语言只不过是工具而已,无所谓,呵呵!
发表于 2016-10-17 02:54:25 | 显示全部楼层
回复 14# cihron


    有句关于语言的经典的话,送给你,慢慢就理解了

    “计算机语言如同祭司手中的神杖,神杖换了,祭司还是祭司,世人还是会把头叩得山响。祭司掌握了与神交流的方法,而世人只看见了神杖。”
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-3 12:50 , Processed in 0.081439 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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