例如,我正在尝试使SAP GUI 740中的属性设置命令列表自动化,以将字段的“ text”属性设置为“ 12345”,如下所示。
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
End If
If Not IsObject(session) Then
Set session = connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
End If
Function Overall()
session.findById("wnd[0]/tbar[0]/okcd").text = "12345"
end function
call Overall
效果很好,也一样:
Function Overall()
set control = session.findById("wnd[0]/tbar[0]/okcd")
control.text = "12345"
end function
也是:
Function Overall()
set control = session.findById("wnd[0]/tbar[0]/okcd")
with control
.text = "12345"
end with
end function
我需要弄清楚如何将这样的函数以字符串形式传递属性名称和值,并对其进行设置。例如:
Function Desired(Input)
GUI_ID = Input(0)
Property_to_change = Input(1)
Value_to_change = Input(2)
session.findById(GUI_ID).Property_to_change = Value_to_change
end function
最好的选项似乎是CallByName,如下所示,但出现类型不匹配错误。
Function Desired(Input)
GUI_ID = Input(0)
Property_to_change = Input(1)
Value_to_change = Input(2)
set control = session.findById(GUI_ID)
CallByName control, Property_to_change, vbSet, Value_to_change
end function
和错误:
Microsoft VBScript runtime error: Type mismatch: 'callbyname'
我不知道这是一个简单的语法问题,还是我使用的是完全错误的语法。我也没有投资CallByName,所以如果有更好或更简单的方法,我全力以赴:)
谢谢大家!
在VB脚本中,可以按以下方式解决任务。
例如:
Function Desired(Input_0, Input_1, Input_2)
GUI_ID = Input_0
Property_to_change = Input_1
Value_to_change = Input_2
set control = session.findById(GUI_ID)
if Property_to_change = "text" then
with control
.text = Value_to_change
end with
session.findById("wnd[0]").sendVKey 0
end if
if Property_to_change = "setFocus" then
with control
.setFocus
end with
end if
'etc.
end function
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
End If
If Not IsObject(session) Then
Set session = connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
End If
session.findById("wnd[0]").maximize
call Desired("wnd[0]/tbar[0]/okcd", "text", "12345")
问候,ScriptMan