[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

C# DLL in Excel

Posted on 2011-10-31
3
Medium Priority
?
274 Views
Last Modified: 2013-12-16
Hi,

I have a c# dll which is referenced by Excel. In my c# project I have 5 classes. Two of which are listed below, the first one is the class called 'clsTest'. The bottom one is the class 'clsStop'. The problem I have is when in VBA I can see the struct from the clsStop class however I cannot see the stuct from the clsTest class. I cannot see any difference between the two classes so confused as to why this is the case?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Using System.Runtime.InteropServices;

namespace SimulatorTypes
{
public struct TDWaveCounter
{
string WaveCount;
string Trend;
}
[ClassInterface(ClassInterfaceType.AutoDual)]
public class clsTest
{
}
}

Open in new window


 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace SimulatorTypes
{
public struct Stops
{
enStops Name;
Boolean Active;
Double ParaValue;
Double AfterNPeriods;
}
[ClassInterface(ClassInterfaceType.AutoDual)]
public class clsStop
{
}
}

Open in new window

0
Comment
Question by:mcs26
  • 2
3 Comments
 
LVL 40
ID: 37056998
What is enStops? It is not a standard type, so VBA might not be able to interpret what it is and thus disregard your structure.

An by the way, you might be better to use classes instead of structures. Because of the way they are handled in memory (stack instead of heap), structures should be small things. it is suggested that they do not take more than 16 bytes.  Look at the structures provided in the framework, they always contains numbers only. A structure with 2 strings such as TDWareCounter will probably end up taking up more than 16 bytes.
0
 

Author Comment

by:mcs26
ID: 37057069
Hi James,

Sorry enStop is a enumeration. VBA is actually able to interpret the stuct & this enumeration from the class clsStop. It is the stuct in the clsTest that does not appear to be reconginsed in VBA, but is in the object browser.

Thanks for the adivse on using struct rather than classes all rather new to this. The reason I have so far been using struct is that I have numerous indicators that have all different properties and was trying to make it easier to store the data and more readable for myself when coding. So say I have 50 indicators (which all have different properties and parameters it would be best to make 50 different classes rather than structs? I guess I could also have a base class for the shared properties the have?

Thanks again,
Mark
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 2000 total points
ID: 37057473
Sorry myself, I misread your question.

And I have no answer now that I look at it the other way around. If the Object Browser sees it, VBA should be able to do see it also. Even if it is not listed in IntelliSense, can you still use it. I have seen that in a couple of cases. The class / property / method is available and works if you code for it, but not listed by IntelliSense.

Could I ask why you are creating your dll in .NET if it is to be used from VBA? Is this because you will need to also use it from .NET applications?VBA was not designed to work with .NET, so it is often awkward to do so. On the other hand, .NET has been designed to work with legacy code through interops, and it is usually a lot easier to have code shared between the 2 environments wirtten in VBA than in .NET.

If your indicators have more than a few properties, mostly numerics (dates and booleans are numeric under the hood), classes might be a better call. This is a case by case situation.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

830 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