How to create global Funtions & Routines

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matthew Hood

    How to create global Funtions & Routines

    I'm at a loss on how to create global functions for my website.
    Essentially, I have several different functions I use throughout my site and
    I want to be able to put these in 1 file and call them from anywhere.
    Currently, I just copy them into each aspx file... Not what I want to do.

    Any help? BTW, I am using WebMatrix to develope the aspx forms.
    TIA
    -Matt


  • MC D

    #2
    Re: How to create global Funtions & Routines

    Welcome to object oriented programming. ;o)

    Each page in your site is a class. You'll note at the top of your
    codebehind file (I'm assuming you have this in webmatrix?) that you specifiy
    a class name for your page... e.g. "Public Class myPage"... this "page" is a
    public class, so it is available to any part of your application. (Assuming
    it exposes the methods you need).

    Lets assume you have a function in your codebehind file that you want to
    access elsewhere in your web application. You can just create an instance
    of the other "page" (class) from within your current codebehind file by
    just stating:

    dim myTool as new myPage()

    where myPage is the class that contains the method you wish to use. For
    example if you had a function that added two numbers in your myPage class
    called "addIt" you could say:

    dim myTool as new myPage()
    dim myresult as Integer = myTool.addIt(nu mber1, number2)

    What you really need to do is have a class library. (just a file with a .vb
    extension) in you application with the classes you wish to implement
    globally, that way when you create an instance of the "tool" you need you
    aren't using all the extra memory neccessary to create an instance of the
    myPage class. (because it inherits from the Page class which has a ton of
    methods, etc..)

    Hope that helps.

    -MC D


    "Matthew Hood" <mshood@qwest.n et> wrote in message
    news:uoU6kcpODH A.3020@TK2MSFTN GP10.phx.gbl...[color=blue]
    > I'm at a loss on how to create global functions for my website.
    > Essentially, I have several different functions I use throughout my site[/color]
    and[color=blue]
    > I want to be able to put these in 1 file and call them from anywhere.
    > Currently, I just copy them into each aspx file... Not what I want to do.
    >
    > Any help? BTW, I am using WebMatrix to develope the aspx forms.
    > TIA
    > -Matt
    >
    >[/color]


    Comment

    • Matthew Hood

      #3
      Re: How to create global Funtions &amp; Routines

      Webmatrix does not use the Codebehind method.
      Initially I created the functions in a .vb file, but when I tried to access
      them from a page, I get an error stating that the routines were not defined.
      Do the vb files have to be compiled?

      TIA-
      Matt

      "MC D" <nospam@earthta lk.com> wrote in message
      news:vfi9po4kc9 np5c@corp.super news.com...[color=blue]
      > Welcome to object oriented programming. ;o)
      >
      > Each page in your site is a class. You'll note at the top of your
      > codebehind file (I'm assuming you have this in webmatrix?) that you[/color]
      specifiy[color=blue]
      > a class name for your page... e.g. "Public Class myPage"... this "page" is[/color]
      a[color=blue]
      > public class, so it is available to any part of your application.[/color]
      (Assuming[color=blue]
      > it exposes the methods you need).
      >
      > Lets assume you have a function in your codebehind file that you want to
      > access elsewhere in your web application. You can just create an instance
      > of the other "page" (class) from within your current codebehind file by
      > just stating:
      >
      > dim myTool as new myPage()
      >
      > where myPage is the class that contains the method you wish to use. For
      > example if you had a function that added two numbers in your myPage class
      > called "addIt" you could say:
      >
      > dim myTool as new myPage()
      > dim myresult as Integer = myTool.addIt(nu mber1, number2)
      >
      > What you really need to do is have a class library. (just a file with a[/color]
      ..vb[color=blue]
      > extension) in you application with the classes you wish to implement
      > globally, that way when you create an instance of the "tool" you need you
      > aren't using all the extra memory neccessary to create an instance of the
      > myPage class. (because it inherits from the Page class which has a ton of
      > methods, etc..)
      >
      > Hope that helps.
      >
      > -MC D
      >
      >
      > "Matthew Hood" <mshood@qwest.n et> wrote in message
      > news:uoU6kcpODH A.3020@TK2MSFTN GP10.phx.gbl...[color=green]
      > > I'm at a loss on how to create global functions for my website.
      > > Essentially, I have several different functions I use throughout my site[/color]
      > and[color=green]
      > > I want to be able to put these in 1 file and call them from anywhere.
      > > Currently, I just copy them into each aspx file... Not what I want to[/color][/color]
      do.[color=blue][color=green]
      > >
      > > Any help? BTW, I am using WebMatrix to develope the aspx forms.
      > > TIA
      > > -Matt
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...