Solved

Reference is not visible in VB6

Posted on 2010-11-17
8
417 Views
Last Modified: 2012-08-14
I have created a Class project in VB.net (vs 2009). I just used regasm to create the .tlb file (thanks for those instructions. I got them here). I have created a strong key, Emailinvoices.snk.pfx.
However after referencing the .tlb file in Excel VBA, I try to create an object with:

Dim objEmailInvoices as new ______  <== But EmailInvoices is not visible in the Intelisense help.

The Properties and Modules of the Class are all declared as Public. What am I missing?

thanks,
pat
0
Comment
Question by:mpdillon
  • 4
  • 3
8 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34159641
0
 

Author Comment

by:mpdillon
ID: 34160093
CodeCruiseer,
The MS article was very helpful. All of the ComVisible attributes were set to TRUE (that is the default but I checked). My Class had another property COMClass and it was set to FALSE. I changed it to TRUE. That did not solve the problem.

I looked at the AssemplyInfo.vb file (use the Show all files button of the Project). I found a line:
<Assembly:ComVisible(False)>   I changed this to True. That did not solve my problem.

The MS article stated the need to have an empty procedure named NEW. That rang a bell so I compared the old project to the new one. To the new project I added:

Public Sub new()
 MyBase.New()
End Sub

After this I was able to see the Class and its Properties in VBA.

After each change, I Ran a Build on the project. Then I regenerated the .TLB file with Regasm. Was the regeneration of the .Tlb file necessary?

Lastly, I compared this project to the one I did several years ago. The older VS 2008 project had the following code at the top of  the Class Module

<Assembly: ClassInterface(ClassInterfaceType.AutoDual)>
<ComClass(SendEmailClass.ClassId, SendEmailClass.InterfaceId, SendEmailClass.EventsId)> _
Public Class SendEmailClass

#Region "COM GUIDs"
    ' These  GUIDs provide the COM identity for this class
    ' and its COM interfaces. If you change them, existing
    ' clients will no longer be able to access the class.
    Public Const ClassId As String = "187d8992-b211-44f7-9bf0-9be98129905c"
    Public Const InterfaceId As String = "2ca24656-528b-42a2-bed0-a1452d70c0de"
    Public Const EventsId As String = "e8f8d4e7-ee4d-47e8-8b30-765111c27ec0"
#End Region

    ' A creatable COM class must have a Public Sub New()
    ' with no parameters, otherwise, the class will not be
    ' registered in the COM registry and cannot be created
    ' via CreateObject.
    Public Sub New()
        MyBase.New()
    End Sub


The New project only has:


<Microsoft.VisualBasic.ComClass()> Public Class Class1
    Public Sub New()
        MyBase.new()
    End Sub

Do I need to modify the new project? Are there negative consequences for how I have it currently structured? If I do need to get the "Assembly .." code into the new project, can you point me to an article that explains how to do it?

thanks,
pat
0
 

Author Comment

by:mpdillon
ID: 34160106
P.S. This code is not intended to run in Excel. I just test in Excel because it is easier to do than to use the embedded VBA in the ERP solution I am working with.
0
 

Author Comment

by:mpdillon
ID: 34160163
The Class and its properties are now visible. However, when I try to access the Properties I receive the following error:
"The Class does not support Automation or does not support the expected interface"

Here is my code:

Dim objPrintInvoices As New EmailInvoices.Class1
'

With objPrintInvoices
    .DatabaseNameString = "demodata"
    .InvNoString = "3741"
    .ReportTypeInteger = 0
    .ServerNameString = "fs-eatemsql"
    .ProcessInvNo
    MsgBox "Invoice Pdf file = " & .PDFFileNameString
End With

It gives the error message at the WITH line.

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 17

Expert Comment

by:Zhaolai
ID: 34161319
Make sure to check "Register for COM Interop" in Project Properties->Compile, see attached screen shot. A .tlb file will be generated automatically.
ScreenShot.png
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 34162375
Notice this point in MS article

"Use the COMClass template in Visual Basic .NET or in Visual Basic 2005. When you add a new class that you intend to expose to COM applications, consider using the COMClass template that is provided by Visual Basic .NET or by Visual Basic 2005. The COMClass template creates a class that includes the COMClassAttribute attribute and generates GUIDs for the CLSID, the Interface ID, and the Event ID that are exposed by your type. Additionally, the COMClass template creates a public constructor without parameters. This is the easiest way to create a new class that follows the guidelines for creating COM callable types."


Did you use the COMClass template?
0
 

Author Closing Comment

by:mpdillon
ID: 34163373
CodeCruiser,
Thanks again. I was not deleting the newly created class and ADDing a COM Class. That is a great article.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34163409
Glad its sorted :-)
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now