vb.net using a .cs class

  • Thread starter Thread starter William Gower
  • Start date Start date
W

William Gower

I was given a c# class to use in my vb.net project. What do i have to do
other than just placing it in my project for my vb.net classes to be able to
use it? Or can I not do that?
 
Call me ignorant but won't it just work?

Have you tried calling the c# proc from VB using VB.NET?

It should work. I have used several c# dll's and called from my VB
routines. Maybe I am missing something but I don't think so.

If you can't just call it, then please write back.

Shane
 
I was given a c# class to use in my vb.net project. What do i have to do
other than just placing it in my project for my vb.net classes to be able to
use it? Or can I not do that?

You can't use a .cs file in a VB.Net project. You must place the .cs file
in its own C# project and then add that project to your solution. You
should then be able to use it with VB.
 
Compile the *.cs file into a class library. You can then reference the assembly in your VB.NET project and use it in your code

You can't mix C# and VB.NET in the same project using Visual Studio.
 
* "William Gower said:
I was given a c# class to use in my vb.net project. What do i have to do
other than just placing it in my project for my vb.net classes to be able to
use it? Or can I not do that?

What you cannot do is adding the C# file to your VB.NET project. One
project, one programming language. If you are using VS.NET Professional
or better, or you have C# Standard, you can create a C# class library,
add the file and set the root namespace in the project properties, let's
say, to 'ClassLibrary1'.

Then you add this project to your solution and add a reference inside
the solution explorer (have a look at the items in the context menus
that are shown when right-clicking projects in solution explorer.

After setting up a reference from your VB.NET project to the C# class
library, you can import the namespace of the class library ('Imports
ClassLibrary1' on top of your VB.NET file, and then use the class
defined in the library.
 
Guess I stand corrected by the other posts.

I do know that I used it. Guess I was able to via the fact that they were
already compiled dll's.
 
as of VS 2005 you can use C# VB J# and C++ code all in the same project and
compiled into one assembly


Chris Dunaway said:
I was given a c# class to use in my vb.net project. What do i have to do
other than just placing it in my project for my vb.net classes to be able to
use it? Or can I not do that?

You can't use a .cs file in a VB.Net project. You must place the .cs file
in its own C# project and then add that project to your solution. You
should then be able to use it with VB.

--
Chris

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
* "Brian Henry said:
as of VS 2005 you can use C# VB J# and C++ code all in the same project and
compiled into one assembly

AFAIK that won't be possible...
 
Hi Herfried,

Seeing all the answers I had from you expected more some links to a
translate tool for C# to VB.net with the sentence "Why would you use C#".

:-)

(Just for fun your explanation is very clear and not echoing seeing the
times of the other posts.)

Cor
 
* "Cor Ligthert said:
Seeing all the answers I had from you expected more some links to a
translate tool for C# to VB.net with the sentence "Why would you use C#".

LOL -- I thought about posting the links, but then I decided to wait for
the OP's reaction...
 
really? because it's in the VS 2005 may preview and works pretty well from
what ive tested ;)
 
* "Brian Henry said:
really? because it's in the VS 2005 may preview and works pretty well from
what ive tested ;)

As far as I see, this doesn't work. I created a new Windows Forms
project and added a C# file. When setting its 'Build Action' to
'Compile', there were numbers of errors because the file didn't contain
VB code.

I still doubt that this will work, but can you describe how you got it
to work?
 
Herfried,
I suspect Brian is using a ASP.NET project.

As my understanding is the same as yours. VS 2005 will not support mixing
languages in a single assembly (project).

ASP.NET is different, as it supports putting any source file in the Code
directory, when the user browses to the web app ASP.NET (not VS.NET) will
take the files in the Code directory and create the appropriate assemblies
out of them...

Jay
 
* "Jay B. Harlow said:
I suspect Brian is using a ASP.NET project.

As my understanding is the same as yours. VS 2005 will not support mixing
languages in a single assembly (project).

ASP.NET is different, as it supports putting any source file in the Code
directory, when the user browses to the web app ASP.NET (not VS.NET) will
take the files in the Code directory and create the appropriate assemblies
out of them...

OK, thank you! I didn't think of that for some reason...
 
Hi Jay,

That is sure for ASPX scripting, (was already with framework 1.0).

However when this will not go with windowforms than I am in doubt if it will
go with compiled asp.net.

Basicly it is using that the same as windowforms, you create a dll, which is
the server apllication.

However I know of course nothing or almost nothing about VS2005.

Cor
 
Hi Jay,

Before you write it, reading it over I think you wrote partially the same
as I, however told it in another way. When you mean with VS.net an builded
DLL than it probably complete the same otherwise that part stays.

Cor
 
Cor,
That is sure for ASPX scripting, (was already with framework 1.0).
The code directory/folder is new for ASP.NET 2.0

Scripting I tend to think of client side, the Code directory is server side,
just as the ASPX itself is server side...

My explanation of the Code folder is based on the information in Alex Homer,
Dave Sussman and Rob Howard's book "A First Look at ASP.NET v. 2.0" from
Addison Wesley.

Of course VS.NET 2005 (Whidbey) is still a beta product and actual specifics
can change.

Hope this helps
Jay
 
Jay,
Scripting I tend to think of client side, the Code directory is server side,
just as the ASPX itself is server side...

Sorry, to say it is not, that is the great misunderstanding all the time. I
do not know if you have ever looked at the VB6 IIS class. I tried it a while
and then there was said that the project was stopped, it was full of bugs.
However it creats a serverside dll for an IS server.

Now we have our VS.studio way as you and I recognize making serverside DLL
applications.

However when you take the samples from the SDK 1.1 it is all a kind of
scripting.
(And most samples on msde are, and therefore mostly difficult for us)

You can make aspx pages and ascx pages. In that you can place your HTML and
language code, however not compile, it is compiled just in time at
serverside. There is no problem to place VB after a C# paragraph.

See this by instance (it is old)

<script language="C#" runat="server">
public string loging
{
get { return loginbox.Text; }
set { loginbox.Text = value; }
}
public string pw
{
get { return pwbox.Text; }
set { pwbox.Text = value; }
}
</script>

I hope I clear with this more what I mean?

Cor
 
Cor,
Sorry, to say it is not, that is the great misunderstanding all the time.
I
You sure did misunderstand my statement! Then again you normally do! :-(

My statement meant to say: Within the context of ASP.NET I tend to think of
& use scripting as client side, the code directory itself is server side.

Obviously for your benifit I should have added: Yes you can do server side
scripting within ASP.NET. However my statement was not including server side
scripting...

If you really don't understand what I am stating, please ask. Do not give me
a dissertations on what you think I don't know. As it simply insults me, and
belittles you.

I consider this matter dropped.

Thanks for understanding.
Jay
 
Jay,

I do not know why you are accusing me in such a low manner.

The only thing I can say is, take your message, go to the mirror, and say it
loud, while you are thinking I am speaking to you.

Cor
 
Back
Top