Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Including files

Reply
Thread Tools

Including files

 
 
Shelly
Guest
Posts: n/a
 
      09-24-2007
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


 
Reply With Quote
 
 
 
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      09-24-2007
"Shelly" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> 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...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
 
 
 
Shelly
Guest
Posts: n/a
 
      09-24-2007

"Mark Rae [MVP]" <(E-Mail Removed)> wrote in message
news:Oh67vnn$(E-Mail Removed)...
> "Shelly" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> 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...


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


 
Reply With Quote
 
Hans Kesting
Guest
Posts: n/a
 
      09-24-2007
> 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


 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      09-24-2007
"Shelly" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> 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...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
Shelly
Guest
Posts: n/a
 
      09-24-2007

"Mark Rae [MVP]" <(E-Mail Removed)> wrote in message
news:%23NVF7dq$(E-Mail Removed)...
> "Shelly" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> 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...


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


 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      09-24-2007
"Shelly" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> 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...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
Shelly
Guest
Posts: n/a
 
      09-24-2007
Thank you. (Yes, I meant the SAME project).

Shelly

"Mark Rae [MVP]" <(E-Mail Removed)> wrote in message
news:%23gY2i9s$(E-Mail Removed)...
> "Shelly" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> 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...
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
including .specification files (or other "dot" files) in RakePackage on Linux/Mac OS X Nathan Beyer Ruby 0 11-15-2009 09:34 PM
How to avoid including C files in other C files in an old code base Raman C Programming 5 06-07-2008 08:43 PM
"Including" multiple files? farmer ASP .Net 5 08-02-2005 04:10 AM
Re: Protect an entire directory (including non-ASP.NET files) Xavier MT ASP .Net 1 08-19-2003 05:57 PM
Re: Protect an entire directory (including non-ASP.NET files) MS News \(MS ILM\) ASP .Net 1 08-19-2003 03:07 PM



Advertisments