Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7745701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:05:18+00:00 2026-06-01T10:05:18+00:00

I have written an assembly in C# which returns a string array, the C#

  • 0

I have written an assembly in C# which returns a string array, the C# code is below:

[ComVisible(true)]
public class PostcodeFinder
{
    public string[] SearchPostcodes(string postCode)
    {
        var searchService = new QuickAddress("http://x.x.x.x:xxxx/")
                                {Engine = QuickAddress.EngineTypes.Singleline, Flatten = true};

        var mPicklist = searchService.Search("GBR", postCode, PromptSet.Types.OneLine);
        var x = mPicklist.Picklist.Items.Count();

        var resultsToReturn = new string[x];

        for (var i = 0; i < x; i++)
        {
            resultsToReturn[i] = mPicklist.Picklist.Items[i].PartialAddress;
        }

        return resultsToReturn;
    }
}

I have then built this assembly, being sure to tick the Register for COM interop box in properties. Then in Microsoft Access, I have added the .tlb file to the references and created a form with a couple of controls (one of which is a Listbox control named lstResults). Under the main button control, I have the following VBA code:

Private Sub btnSearch_Click()

    Dim postcodeToSearch As String
    postcodeToSearch = Me.txtPostcode

    Dim c As New PostcodeFinder
    Dim results

    results = c.SearchPostcodes(postcodeToSearch)

End Sub

Edit: This runs without error, however when I query the Immediate window with ?results after putting some dummy code below to allow me to place a breakpoint, I get the following error:

Run-time error ’13’ – Type mismatch

Effectively I want to rewrite the following C# code in VBA:

var results = c.SearchPostcodes(postcodeToSearch);

foreach(var x in results)
{
    lstResults.Items.Add(x);
}

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:05:19+00:00Added an answer on June 1, 2026 at 10:05 am

    Updated Answer: Instead of returning string[], try returning object instead:

    [ComVisible(true)]
    public class PostcodeFinder
    {
        public object SearchPostcodes(string postCode)
        {
            //Unchanged code
    
            return (object)resultsToReturn;
        }
    }
    

    You will still get the type mismatch error in the immediate window when performing ?results (you need to specify an index such as ?results(0)), however you are able to iterate through the array as:

    results = c.SearchPostcodes(postcodeToSearch)
    Dim result As Variant
    For Each result In results
        MsgBox result
    Next result
    

    Original Answer: You need to instantiate the PostcodeFinder class. In your btnSearch_Click subroutine, try:

    Dim c As New PostcodeFinder
    Dim results
    
    results = c.SearchPostcodes(postcodeToSearch)
    

    Alternatively, you could separate the declaration from the instantiation as:

    Dim c As PostcodeFinder
    Dim results
    Set c = New PostcodeFinder
    
    results = c.SearchPostcodes(postcodeToSearch)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an assembly, written in C++\CLI, which uses some of enumerations, provided by
I have a project which has several custom descriptors written for the assembly plugin.
I have written a class library in C# (mydll.dll) which accesses a third party
I have written some Assembly code for parallel processing using ARM Wireless MMX technology
I have some code I've written in PHP for consuming our simple webservice, which
I have a method in .NET (C#) which returns string[][] . When using RegAsm
I have written an assembly which is integrated in sql server, providing some stored
I have written an assembly I don't want other people to be able to
I have written some code in my VB.NET application to send an HTML e-mail
I have written a ruby script which opens up dlink admin page in firefox

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.