Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Reference is not visible in VB6

Posted on 2010-11-17
8
Medium Priority
?
469 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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
 
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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

610 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