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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Classes in VB

Status
Not open for further replies.

NeilV

Programmer
Oct 14, 2002
117
GB
Hello,

I have created a class file in C# and I can use it fine in my C# web pages. However, I cannot seem to get them to work in my VB.Net pages. I am compiling the Class file into a DLL and placing it in the bin directory.
I am trying to use the class in the following way:
Dim Utility() MyUtil = new Utility
I have put the same import staement in both the c# and vb versions.

Any one any ideas?

Neil
 
Neil - what do you mean by "it is not working"? One thing may be - if you compile and place a C# dll in the bin or a VB.net project, and you are using VS.net, you still need to add a reference to the dll from the VB.net project before you can compile the VB.net project.
Mark [openup]
 
Mark,

Sadly I am not using VS.net i'm using WebMatrix which doesn't allow you(I'm not aware of) to reference DLL's.
I have however, got the following line in my aspx page:

<%@ import Namespace=&quot;MyClass&quot; %>

I have created a very simple page using C# to use some of the methods from MyClass and it works fine. So it suggests that there is a syntax error in my VB code. The error message that I get is:

BC30182: Type expected.
Line 18: Dim My as MyClass = new MyClass()

Any ideas?

Neil
 
Well there you go then. VB is not C#.
Try

dim My as new MyClass()

Mark [openup]
 
By the way, why not just do the ASP.net page in C#, if that is your preffered language? Mark [openup]
 
Neil
Sorry I was half asleep when I said that your VB constructor was wrong. I'm just not used to doing it this way.
But I did manage to get a C# class working in a vb asp.net page using web matrix. At first I got the same error as you (type expected). I think this is because you have created the C# class with a namespace of MyClass. You also need the name of the class itself.

This code works for me

Code:
sub page_load(ByVal sender As System.Object, ByVal e As System.EventArgs) handles mybase.load
dim c as new Hello.Class1()
textbox1.text = c.hello
end sub

And all you should have to do is drop the dll into the bin folder - you should not need to set a reference to it.

Hope this helps.

Mark [openup]
 
Thanks Mark, that does the job nicely!

Neil

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top