0

I have a system function in VB.net that return a list of Strings (I've debugged this function). And right now I need to call that system function in VBScript. How can I get that list of strings?

enter image description here

VB.net system function

Public Function someList As List(Of String)
    Return List
End Function

VBScript:

Dim results
Set results = System.someList

For Each result In results
    wscript.echo result
Next
7
  • Check out this link How to call a .NET DLL from a vb script Commented Jan 20, 2019 at 21:47
  • Hi, thanks for your reply. I have some system functions that need to be called by the vbscript file. And all the others functions can be called successful. Only this function returns a List that couldn't be called. So I think the return type of this function might cause the problem. I wonder can I still use List as the return type? Or I need to change the return type to ArrayList? Or do you have any suggestions for me? Commented Jan 20, 2019 at 22:10
  • 2
    VBScript cannot use .Net APIs unless the .Net class exposes a COM interface (like ArrayList or StringBuilder). Commented Jan 20, 2019 at 22:12
  • Also, all the other functions are called by the function name. I use something like this: wscript.echo System.FunctionName. And when I run the file it gives me the correct value in the popup window Commented Jan 20, 2019 at 22:12
  • 1
    WScript is an intrinsic object provided by the runtime environment (more specifically by the interpreters wscript.exe and cscript.exe). The same does not apply to the .Net System namespace. Commented Jan 20, 2019 at 22:31

1 Answer 1

1

The problem is that VBScript doesn't understand Generic classes (or is it COM that is the problem?), so you'll have to convert your list to something non-generic such as ArrayList.

I had the same problem when trying to use my C# library from VBScript and I wrote a simple conversion function (in C#) to overcome this problem:

    public ArrayList toArrayList(IEnumerable collection)
    {
        var arrayList = new ArrayList();
        foreach (object element in collection)
        {
            arrayList.Add(element);
        }
        return arrayList;
    }

Some more helper functions I needed to get things working can be found here: ScriptingInteropHelper

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.