Conversion from type 'String' to type 'String' is invalid

I am porting an old excel addin that was written in VBA for VB.NET. Excel addin interacts with several external COM objects. Code sorting looks like this:

Dim hurr as Object
Dim durr as String

hurr = CreateObject("COM Object")
durr = hurr.getString

What I'm trying to do is read a line from a COM object and get it in durr for use later in my program.

This second line leads to the exception posted above. If I try casting with CStr / CType, I get the same exception. The visual studio viewport reports the type hurr.getString as "System .__ ComObject", while the VBA viewer reports the type as "Option / Object / String". Microsoft.VisualBasic.Information.TypeName (hurr.getString) says the type is "String". Any ideas on how I should work on this?

Thank!

+3
source share
1 answer

This is ridiculous, but I decided that I would post an answer here for completeness. The solution was to add a pair of brackets to the end of hurr.getString

therefore, the working code is as follows:

Dim hurr as Object
Dim durr as String

hurr = CreateObject("COM Object")
durr = hurr.getString()

- . , com .

+1

Source: https://habr.com/ru/post/1726277/


All Articles