473,406 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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
Nov 17 '05 #1
2 4021
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(number1, 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" <ms****@qwest.net> wrote in message
news:uo**************@TK2MSFTNGP10.phx.gbl...
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

Nov 17 '05 #2
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" <no****@earthtalk.com> wrote in message
news:vf************@corp.supernews.com...
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(number1, 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" <ms****@qwest.net> wrote in message
news:uo**************@TK2MSFTNGP10.phx.gbl...
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


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Dan | last post by:
Quick question about passing variables to subs to reduce the need for publicly declared variables in VB6. If I have an event sub (MouseDown) that runs a few lines of code, how can I use a variable...
22
by: nobody | last post by:
hello everybody, is there a way of creating an array with help of a function that would accept the name of this array as a parameter and then create global Array type variable of that name? so...
3
by: seberino | last post by:
At top of a module I have an integer like so... foo = 4 In a function in that module I know I need to do 'global foo' to get at the value 4. .... IIRC, for dictionaries you DO NOT have...
4
by: Max | last post by:
Hello everyone, and thank you in advance for all of your help! I have a tblPrint table in Access 2002. Its structure is as follows: tblPrint ------------------ Name, Text Address1, Text...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
7
by: Michael | last post by:
Hi newsgroup, as the subject indicates I am looking for an advice using global variables. I am not if this problem is more about style then C. If its wrong in thi group, sorry. So I have a...
9
by: tshad | last post by:
I have an example I copied from "programming asp.net" (o'reilly) and can't seem to get the Sub (writefile) to execute. It displays all the response.write lines that are called directly, but not...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
4
by: ahagley | last post by:
The problem: 1) I'm not a programmer, most of the time I'm a physicist, but I do numerical simulation. 2) I have a DLL that I want to use functions from. I have the .h file associated with the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.