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

[AU3基础] 哪位老师有空能帮我把这段代码优化一下,谢谢!

  [复制链接]
发表于 2012-12-19 20:13:58 | 显示全部楼层 |阅读模式
这是一段控制期货交易软件的代码,总感觉能有更简单的写法。
                                If FileExists($TBszlj & "User" & $TBloginname & "\Desktop\我的工作区\工作区1.wsp") Then
                                        WinMenuSelectItem("交易开拓者平台(旗舰版)", "", "文件(&F)", "打开工作区")
                                        WinWait("打开", "", 9)
                                        ControlFocus("打开", "", "Edit1")
                                        ControlSetText("打开", "", "Edit1", "工作区1.wsp")
                                        ControlFocus("打开", "", "Button1")
                                        ControlClick("打开", "", "Button1")
                                        WinWait("交易开拓者平台(旗舰版)", "工作区1", 5)
                                EndIf
                                If FileExists($TBszlj & "User" & $TBloginname & "\Desktop\我的工作区\工作区2.wsp") Then
                                        WinMenuSelectItem("交易开拓者平台(旗舰版)", "", "文件(&F)", "打开工作区")
                                        WinWait("打开", "", 9)
                                        ControlFocus("打开", "", "Edit1")
                                        ControlSetText("打开", "", "Edit1", "工作区2.wsp")
                                        ControlFocus("打开", "", "Button1")
                                        ControlClick("打开", "", "Button1")
                                        WinWait("交易开拓者平台(旗舰版)", "工作区2", 5)
                                EndIf
                                If FileExists($TBszlj & "User" & $TBloginname & "\Desktop\我的工作区\工作区3.wsp") Then
                                        WinMenuSelectItem("交易开拓者平台(旗舰版)", "", "文件(&F)", "打开工作区")
                                        WinWait("打开", "", 9)
                                        ControlFocus("打开", "", "Edit1")
                                        ControlSetText("打开", "", "Edit1", "工作区3.wsp")
                                        ControlFocus("打开", "", "Button1")
                                        ControlClick("打开", "", "Button1")
                                        WinWait("交易开拓者平台(旗舰版)", "工作区3", 5)
                                EndIf
                                If FileExists($TBszlj & "User" & $TBloginname & "\Desktop\我的工作区\工作区4.wsp") Then
                                        WinMenuSelectItem("交易开拓者平台(旗舰版)", "", "文件(&F)", "打开工作区")
                                        WinWait("打开", "", 9)
                                        ControlFocus("打开", "", "Edit1")
                                        ControlSetText("打开", "", "Edit1", "工作区4.wsp")
                                        ControlFocus("打开", "", "Button1")
                                        ControlClick("打开", "", "Button1")
                                        WinWait("交易开拓者平台(旗舰版)", "工作区4", 5)
                                EndIf
                                If FileExists($TBszlj & "User" & $TBloginname & "\Desktop\我的工作区\工作区5.wsp") Then
                                        WinMenuSelectItem("交易开拓者平台(旗舰版)", "", "文件(&F)", "打开工作区")
                                        WinWait("打开", "", 9)
                                        ControlFocus("打开", "", "Edit1")
                                        ControlSetText("打开", "", "Edit1", "工作区5.wsp")
                                        ControlFocus("打开", "", "Button1")
                                        ControlClick("打开", "", "Button1")
                                        WinWait("交易开拓者平台(旗舰版)", "工作区5", 5)
                                EndIf
                                If FileExists($TBszlj & "User" & $TBloginname & "\Desktop\我的工作区\工作区6.wsp") Then
                                        WinMenuSelectItem("交易开拓者平台(旗舰版)", "", "文件(&F)", "打开工作区")
                                        WinWait("打开", "", 9)
                                        ControlFocus("打开", "", "Edit1")
                                        ControlSetText("打开", "", "Edit1", "工作区6.wsp")
                                        ControlFocus("打开", "", "Button1")
                                        ControlClick("打开", "", "Button1")
                                        WinWait("交易开拓者平台(旗舰版)", "工作区6", 5)
                                EndIf
                                If FileExists($TBszlj & "User" & $TBloginname & "\Desktop\我的工作区\工作区7.wsp") Then
                                        WinMenuSelectItem("交易开拓者平台(旗舰版)", "", "文件(&F)", "打开工作区")
                                        WinWait("打开", "", 9)
                                        ControlFocus("打开", "", "Edit1")
                                        ControlSetText("打开", "", "Edit1", "工作区7.wsp")
                                        ControlFocus("打开", "", "Button1")
                                        ControlClick("打开", "", "Button1")
                                        WinWait("交易开拓者平台(旗舰版)", "工作区7", 5)
                                EndIf
                                If FileExists($TBszlj & "User" & $TBloginname & "\Desktop\我的工作区\工作区8.wsp") Then
                                        WinMenuSelectItem("交易开拓者平台(旗舰版)", "", "文件(&F)", "打开工作区")
                                        WinWait("打开", "", 9)
                                        ControlFocus("打开", "", "Edit1")
                                        ControlSetText("打开", "", "Edit1", "工作区8.wsp")
                                        ControlFocus("打开", "", "Button1")
                                        ControlClick("打开", "", "Button1")
                                        WinWait("交易开拓者平台(旗舰版)", "工作区8", 5)
                                EndIf
                                If FileExists($TBszlj & "User" & $TBloginname & "\Desktop\我的工作区\工作区9.wsp") Then
                                        WinMenuSelectItem("交易开拓者平台(旗舰版)", "", "文件(&F)", "打开工作区")
                                        WinWait("打开", "", 9)
                                        ControlFocus("打开", "", "Edit1")
                                        ControlSetText("打开", "", "Edit1", "工作区9.wsp")
                                        ControlFocus("打开", "", "Button1")
                                        ControlClick("打开", "", "Button1")
                                        WinWait("交易开拓者平台(旗舰版)", "工作区9", 5)
                                EndIf
发表于 2012-12-19 20:27:23 | 显示全部楼层
好乱啊。神魔东西!
 楼主| 发表于 2012-12-19 20:40:26 | 显示全部楼层
猛然看是挺乱的,其实就是依次检测打开9个工作区而已。
发表于 2012-12-19 20:44:12 | 显示全部楼层
本帖最后由 netegg 于 2012-12-19 20:48 编辑

[au3]for $i = 1 to 9
  if FileExists($TBszlj & "User\" & $TBloginname & "\Desktop\我的工作区\工作区" & $i &".wsp") then
       WinMenuSelectItem("交易开拓者平台(旗舰版)", "", "文件(&F)", "打开工作区")
       WinWait("打开", "", 9)
       ControlFocus("打开", "", "Edit1")
       ControlSetText("打开", "", "Edit1", "工作区" & $i & ".wsp")
       ControlFocus("打开", "", "Button1")
       ControlClick("打开", "", "Button1")
       WinWait("交易开拓者平台(旗舰版)", "工作区" & $i, 5)
  endif
next[/au3]
 楼主| 发表于 2012-12-19 20:59:14 | 显示全部楼层
谢谢!谢谢!我这就去把这段代码该换了。。。
发表于 2012-12-23 11:33:09 | 显示全部楼层
楼主辛苦了!
发表于 2012-12-23 19:24:14 | 显示全部楼层
好乱啊。
发表于 2012-12-24 19:25:56 | 显示全部楼层
恳求二楼楼主换个头像!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-2 14:43 , Processed in 0.079724 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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