Very Confused: Class, Imports, ...


S

Shapper

Hello,

I am working in a web site where all the code is placed in aspx.vb
files.
After a while I realized that many functions included in my aspx.vb
files where common to all pages.

I created a new file named common.vb where I created a class named
common and where I place all common functions:

Imports System

Public Class Common
Public Shared Sub MyFunction01()
...
End Sub
...
End Class

In my aspx.vb file I have:

Imports Common

Public Class myPage

Inherits System.Web.UI.Page
Private Sub Page_Load(
MyFunction01()
End Sub

This is all I have. I get the error:
Namespace or Type 'common' for the Imports 'common' cannot be found.

Basically all I need is to use Common functions in my aspx pages class.

Can someone tell me specifically what am I doing wrong?

Thanks,
Miguel
 
Ad

Advertisements

G

Guest

Imports Namespace, or using Namespace in c#, is just a shortcut. You don’t
have to use it. For example, in following code
Dim dap As System.Data.SqlClient.SqlDataAdapter

If you use Imports System.Data.SqlClient, you can write it in short

Dim dap As SqlDataAdapter

In your case, the Common is a class rather than a Namespace. You cannot use
Imports Common.


HTH

Elton Wang
(e-mail address removed)
 
J

Juan T. Llibre

Shapper,

what you need to do is compile common.vb to common.dll using the
command-line compiler (vbc.exe) and reference *that* in your VS.NET project.

vbc /t:library /out:common.dll common.vb

If you need to import .Net classes, include them in your command line:
vbc /t:library /r:system.dll /r:system.web.dll /out:common.dll common.vb

Once your assembly ( common.dll ) is compiled,
place it in the /bin directory of your application
and you will be able to call any of its functions.




Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================
 
S

Shapper

Hello,

So compiling it is the only way?
Isn't it possible to make this work without compiling the common.vb?

Thanks,
Miguel
 
S

Shapper

Hello Juan,

I use Web Matrix because I feel it's simpler and faster to develop.
I also have Visual Studio 2003. Is it possible to use the command-line
compiler without needing to install Visual Studio?

Thanks,
Miguel
 
Ad

Advertisements

J

Juan T. Llibre

Sure, Miguel, you can do that without either.

Just open a command window ( cmd.exe );
make sure that the .Net Framework directory is in your path
( the .Net dir is where the compilers are located (vbc.exe, csc.exe));
navigate to the directory where you have your .vb files,
and run the compile command :

vbc /t:library /out:common.dll common.vb

If you need to import .Net classes, include them in your command line:
vbc /t:library /r:system.dll /r:system.web.dll /out:common.dll common.vb

common.dll will be created/compiled in the current directory.

Move it to the /bin directory of your application and fire away.
If you want to have VS.NET use it, reference it in your project.



Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top