Including files

Discussion in 'ASP .Net' started by Shelly, Sep 24, 2007.

  1. Shelly

    Shelly Guest

    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
     
    Shelly, Sep 24, 2007
    #1
    1. Advertising

  2. "Shelly" <> wrote in message
    news:...

    > 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
     
    Mark Rae [MVP], Sep 24, 2007
    #2
    1. Advertising

  3. Shelly

    Shelly Guest

    "Mark Rae [MVP]" <> wrote in message
    news:Oh67vnn$...
    > "Shelly" <> wrote in message
    > news:...
    >
    >> 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
     
    Shelly, Sep 24, 2007
    #3
  4. Shelly

    Hans Kesting Guest

    > 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
     
    Hans Kesting, Sep 24, 2007
    #4
  5. "Shelly" <> wrote in message
    news:...

    > 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
     
    Mark Rae [MVP], Sep 24, 2007
    #5
  6. Shelly

    Shelly Guest

    "Mark Rae [MVP]" <> wrote in message
    news:%23NVF7dq$...
    > "Shelly" <> wrote in message
    > news:...
    >
    >> 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
     
    Shelly, Sep 24, 2007
    #6
  7. "Shelly" <> wrote in message
    news:...

    > 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
     
    Mark Rae [MVP], Sep 24, 2007
    #7
  8. Shelly

    Shelly Guest

    Thank you. (Yes, I meant the SAME project).

    Shelly

    "Mark Rae [MVP]" <> wrote in message
    news:%23gY2i9s$...
    > "Shelly" <> wrote in message
    > news:...
    >
    >> 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
     
    Shelly, Sep 24, 2007
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MS News \(MS ILM\)
    Replies:
    1
    Views:
    429
    Scott Schluer
    Aug 19, 2003
  2. Xavier MT
    Replies:
    1
    Views:
    613
    Scott Schluer
    Aug 19, 2003
  3. farmer

    "Including" multiple files?

    farmer, Aug 2, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    626
    farmer
    Aug 2, 2005
  4. Raman
    Replies:
    5
    Views:
    385
    Lew Pitcher
    Jun 7, 2008
  5. Nathan Beyer
    Replies:
    0
    Views:
    125
    Nathan Beyer
    Nov 15, 2009
Loading...

Share This Page