首页 > 解决方案 > How to return object to UiPath in VBA?

问题描述

I am trying to return an object from function Find123. I have called it from sub procedure Retrieve123.

When I comple it says function not defined and it highlights the CObj method.

Could you tell me a way to convert integer or string into object and return it in VBA?

Sub Retrieve123()
    Call Find123()
End Sub

Function Find123()As Object
    Dim val As String
    val="100"
    Dim obj As Object
    Set obj=CObj(val)
    Set Find123 = obj
End Function

This is how I get the error message enter image description here

When I assign the string value into the function it gives this type mismatch error.
enter image description here

I need to convert the string into object because in UiPath we can only return type object as the Invoke VBA activity's output is object type.

标签: excelvbauipath

解决方案


您不必将任何内容转换为对象,但 UiPath 将Invoke VBA活动的返回值视为对象(因为它不知道返回的是什么)。您可以安全地从您的函数返回一个原始类型 -integer在您的情况下 - 将其存储在 UiPath 中的对象类型变量中,然后再次将其转换为整数。

这是一个普遍的例子。注意resultis 类型objectwhileiinteger. 在Assign活动内部,i正在被强制转换为integer.

VB.NET 等价物:

i = CType(result, Integer)

UiPath 中的类型转换


推荐阅读