Including files

S

Shelly

Please tell me the best way to do this (I am still new to VB.NET and ASPX)
as this should very easy for anyone with any experience to answer.

In the code behind file (filename.aspx.vb), I import things that are
namespace imports in the main file (filename.aspx). These are from the core
set. I would also like to have a set of functions that I write and use in
many pages, so that I write them once and for all and be done with it
without having to copy them. The way I envision is to include a file that
contains these functions, but I don't know how to do that here and my
searching didn't turn up anything. Note: this in not for including in the
aspx file. It is for the VB file.

(Coming from php there are several commands that could be used eg include,
require and require_once). How do I do it in VB.NET? If it is more
complicated than that, please direct me to some code samples.

Shelly
 
M

Mark Rae [MVP]

Please tell me the best way to do this (I am still new to VB.NET and ASPX)
as this should very easy for anyone with any experience to answer.

In the code behind file (filename.aspx.vb), I import things that are
namespace imports in the main file (filename.aspx). These are from the
core set. I would also like to have a set of functions that I write and
use in many pages, so that I write them once and for all and be done with
it without having to copy them. The way I envision is to include a file
that contains these functions, but I don't know how to do that here and my
searching didn't turn up anything. Note: this in not for including in the
aspx file. It is for the VB file.

(Coming from php there are several commands that could be used eg include,
require and require_once). How do I do it in VB.NET? If it is more
complicated than that, please direct me to some code samples.

1) Create a new class called MyFunctions

2) Create a new function e.g.

Public Shared MyFunction(MyString As String) As String

3) Then, anywhere else in your VB.NET code:

Dim MyString As String = MyFunctions.MyFunction("Hello")


I *think* the above is correct - I never go anywhere near VB.NET...
 
S

Shelly

Mark Rae said:
1) Create a new class called MyFunctions

2) Create a new function e.g.

Public Shared MyFunction(MyString As String) As String

3) Then, anywhere else in your VB.NET code:

Dim MyString As String = MyFunctions.MyFunction("Hello")


I *think* the above is correct - I never go anywhere near VB.NET...

Thanks Mark, but that was not what I was asking. If that class is in some
file called MyFunctions.vb or Myfunctions.aspx.vb (or whatever extension it
should be), how to I include that file in my thisPage.aspx.vb?

It would be the same for c#. I don't know what the code-behind is for c#,
but I guess it is cs. If so, how would I include that MyFunctions.aspx.cs
or MyFunctions.cs (or whatever extension) into thisPage.aspx.cs?

Shelly
 
H

Hans Kesting

Please tell me the best way to do this (I am still new to VB.NET and
ASPX) as this should very easy for anyone with any experience to
answer.

In the code behind file (filename.aspx.vb), I import things that are
namespace imports in the main file (filename.aspx). These are from
the core set. I would also like to have a set of functions that I
write and use in many pages, so that I write them once and for all and
be done with it without having to copy them. The way I envision is to
include a file that contains these functions, but I don't know how to
do that here and my searching didn't turn up anything. Note: this in
not for including in the aspx file. It is for the VB file.

(Coming from php there are several commands that could be used eg
include, require and require_once). How do I do it in VB.NET? If it
is more complicated than that, please direct me to some code samples.

Shelly

You don't "include" files. Instead you build classes that you use from
within other classes.
If that library-class is in the same project (assembly) as the class
you want to use it from, you can just use it (you might want to use
the complete namespace-path at first).
If the class is in a different assembly, then the project you want to
use it from must have a "reference" to that assembly (right-click
the project, choose 'add reference').

Hans Kesting
 
M

Mark Rae [MVP]

Thanks Mark, but that was not what I was asking. If that class is in some
file called MyFunctions.vb or Myfunctions.aspx.vb (or whatever extension
it should be), how to I include that file in my thisPage.aspx.vb?

You don't - you simply call the function from within your code.

Read me post again...
 
S

Shelly

Mark Rae said:
You don't - you simply call the function from within your code.

Read me post again...

Let me get this straight. You include that class in some file, say
MyFunctions.vb and that file is in the project. Then. BEING IN THE PROJECT
is what makes it available to other files?

Shelly
 
M

Mark Rae [MVP]

You include that class in some file, say MyFunctions.vb

Yes - you can have each class in its own code file, or you can include
several classes in the same code file - makes no difference whatsoever to
the compiler...
and that file is in the project.
Yes.

Then. BEING IN THE PROJECT is what makes it available to other files?

Er, the fact that it's in the same project... :)

The Shared keyword before the function name means that it can be called
directly without requiring an instantiation of its class...
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top