vbscript - 使用 VBS 执行字符串作为属性在 SAP 中设置值
问题描述
我正在尝试自动化 SAP GUI 740 中的属性设置命令列表,例如,将字段的“文本”属性设置为“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")
推荐阅读
- javascript - 在尊重其顺序的同时将对象附加到数组
- python - 在表单中过滤查询集
- regex - 带有分隔符的正则表达式以获取价值
- json - 使用 Spark 自定义模式的 Json 到 Parquet
- python - 线程/多处理 - 匹配搜索具有 600k 个术语的 60gb 文件
- android - 带有 ListView 和底部 TextField 的 Flutter AlertDialog
- javascript - 将所有输入值自动保存到 localStorage 并在页面重新加载时恢复它们
- r - 大型运行无法保存为对象
- sql - 所有值和单独组的平均值
- swift - UIPanGestureRecognizer Swift Capture 相对翻译