哪位老师有空能帮我把这段代码优化一下,谢谢!
这是一段控制期货交易软件的代码,总感觉能有更简单的写法。 If FileExists($TBszlj & "User\" & $TBloginname & "\Desktop\我的工作区\工作区1.wsp") ThenWinMenuSelectItem("交易开拓者平台(旗舰版)", "", "文件(&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 好乱啊。神魔东西! 猛然看是挺乱的,其实就是依次检测打开9个工作区而已。 本帖最后由 netegg 于 2012-12-19 20:48 编辑
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 谢谢!谢谢!我这就去把这段代码该换了。。。 楼主辛苦了!{:face (303):} 好乱啊。{:face (114):} 恳求二楼楼主换个头像!
页:
[1]