Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to call method written in VB.NET from C# project

Status
Not open for further replies.

salooo

Programmer
Sep 11, 2003
30
US
Hi,
I am using VS.NET 2003 and I am working on a report in Crystal. I am getting the the required info from another form's method which was written in VB.NET. I am not sure how I can call that method from C# !!!!

My co-worker has created the login screen and she has done her part in VB. I am trying to call a function in her peroject from my C# project. All of the reports are done in my C# project. We have combined the two and my project gets called by her project as we have created a solution and have added both projects to that solution. My C# project has an output type of class library.

I know that we can convert a project into a class library and then reference it in our project. But in this case I can't do that because the information I need is in the project that has an output type of windows app. I can't change it to a class library !!

I want to call a method contained in another project with an output type "windows application" that was written in VB.NET, and that project contains a reference to my project which has an output type of "class library".
I want to get some info from that parent project and pass some value from it to the C# project that I need to include in my report.

Please help me find a way to get access to another project's form's data without converting the project into a class library.


I hope this clarifies my question.

Anxiously waiting for a response.

Thanks
 
You might have a problem with setting/choosing the startup project for your solution. Class libraries typically aren't good candidates for a startup project unless you intend them to be called from somewhere else. Usually, when writing a Windows Forms application, you'll want a Windows Forms-based project to be your startup project. So maybe, if you don't want your dev-partner's project to be the startup, you could create a third project as a Windows Forms project that would just call your class library (which would then call the other project as needed).

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
So really this is about passing information between two separate applications (currently). You'd have the same problem if they were both C#.

Chip's second alternative is really the best - create a new "application" which is the parent of the other two applications and can server as a conduit for information.
 
Hi,
Thank you for your comments. I tried taking the approach to create a new solution and add my other projects to this new solution. When I run the program it runs fine, but when I try to add the VB project (now converted into a clas library) to my C# project it gives me an error saying "A reference to 'XYZ' could not be added. Adding this project as a reference would cause a circular dependency."

How can I overcome this issue ????

Anticipating help soon.

P.S. my new solution is designed as follows;
1) the main project (output type is Windows application)
2) the VB project containing the LogIn info that I want to call in my C# project.(output type is a class library)
3) the C# project with all the reports that need some info from the VB project. (output type is a class library)

Thanks.
 
I don't think you should need to add the project to the C# project if they are both already part of the same parent solution (if I understand what you are doing).

If they both part of the same parent solution, that's why you get that error if you are try to add the VBClassLibrary to the C# project. You should be able to use the appropriate namespace from the VBClassLibrary in the C# project.

If you created the class library without explicitly creating a namespace, you'll have to look at the class library project properties to see what namespace was assigned. By default, it is something like "WindowsClassLibrary1" or something.

d-
 
Hi d,
Well actually I have not added the C# project to the new Main project. I have just added the VB project to the new project but I have added the C# project to the new solution as I have to have it there in order to be able to allow the VB project to call it.

As I mentioned previously right now the new solution conatins 3 projects i.e.,
1) the main project (output type is Windows application)
2) the VB project containing the LogIn info that I want to call in my C# project. Also this projects calls my C# project(output type is a class library)
3) the C# project with all the reports that need some info from the VB project. (output type is a class library)

The problem I am having is that I have added the VB project to my Main project and VS is not allowing me to add this reference again to my C# project as it is creating a circular dependency.

I hope this clarifies my situation.

I would appreciate some help :-(
 
Hi there,
I have identified the problem... Its causing trouble because I am calling the C# project from the VB project and then I am trying to call the VB project from my C# project. It only allows me to call one project from another project only once. I can add the reference of the VB project to my Main but it wont allow me to add a reference in the C# project.

Help !!!!
 
You'll need to make a late-bound call from one call direction, either from VB to C#, or vice-versa. Use the System.Activator class to do this - it has a couple of methods, one of which will probably do what you need.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Hi Chip H,

If possible can you give me a brief code example of how we can do this ???

I would really appreciate your kind help.

Thanks
 
The online help should have one. Or a quick google search will turn up all kinds of stuff.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Hi guys,

Thank you all for your comments and help. I have found a solution. But there is one more thing that I cant quite figure out. May be you know how to deal with it.

I have added a few parameter fields in my reports and have added code to update the fields once I run them. The program is working fine except that every first time the report loads up, it shows me the ugly "Enter Parameter Value" screen.
I need to know how I can get rid of this screen and hide it???????

Any help would be greatly appreciated.

Thanks.
Sal
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top