1、使用如下可优化代码:
with
对象 一个对象或返回值为一个对象的函数
语句 (一个对象上操作的一条或多条语句)
end with
举例如下:
Window("Flight Reservation").WinComboBox("Fly From:").Select "London"
Window("Flight Reservation").WinComboBox("Fly To:").Select "Los Angeles"
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select "19097 LON "
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
更改后的语句为
With Window("Flight Reservation") ---对象
.WinComboBox("Fly From:").Select "London" ---语句
.WinComboBox("Fly To:").Select "Los Angeles"
.WinButton("FLIGHT").Click
With .Dialog("Flights Table")
.WinList("From").Select "19097 LON "
.WinButton("OK").Click
End With 'Dialog("Flights Table")
End With 'Window("Flight Reservation")