Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I resuse code 1

Status
Not open for further replies.

whateveragain

Programmer
Apr 20, 2009
92
US
How can I reuse code without using code snippets or cutting and pasting. I was hoping that I could use some sort of class, but it seems that classes are meant for the entire page or a portion of the page. I don't want to use snippets because if a change is needed, I'll need to go to each page that I placed the snippet. If possible I'd like to be able to change the code in one place. An example of the type of code I want to duplicate is as follows:

Sub getrank()
Dim Rank2 As String
Dim selections As String
Dim wholestring As String
Dim lno2 As Integer
Dim whole2string As String

whole2string = Session("selections")
selections = Session("Selections")
lno2 = InStr(1, Session("Selections"), "Rank2")
If lno2 = 0 Then
lno2 = InStr(1, Session("Selections"), "Rank2")
End If
lno2 = lno2 + 1
whole2string = Session("Selections") & Space(1)
rank2 = whole2string.Substring(lno2 + 26, 1)
End Sub
 
Are you referring to a page as a web page? If so, simply save the code in its own file (code.vbs) and call it on the page

HTML
Code:
<script language="VBScript" src="code.vbs"></script>

This way, you only need to change code.vbs and not every single "page"

-Geates


"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
- Martin Golding

"There are seldom good technological solutions to behavioral problems."
- Ed Crowley, Exchange guru and technology curmudgeon
 
And if you use ASP you may use this syntax:
<!--#include virtual="/path/to/script"-->

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top