We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

How to create a library asp of functions and procedure

hidrau
hidrau asked
on
Medium Priority
321 Views
Last Modified: 2006-11-18
Hello guys, I don't know if what I want is possible, I would like to create a file.asp where is gonna be my library.
In delphi I can do that and what I only need is to call the unit and after all the functions or procedure from my library
I can call.

If it is possible, I need an example how to call the functions and how they should be declared in the library. Thanks

Alex
Comment
Watch Question

Commented:
Use classes - they work great



example:


Class Example

Public Function ExampleFunction()
DoSomething
End Function

End Class





To call on it simply do this:

Set objExample = New Example

call objExample.ExampleFunction

Set objExample = Nothing



Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
I make a file.asp with this lines:

Class Example

Public Function ExampleFunction()
DoSomething
End Function

End Class

is it?

Commented:
yea, but replace the function with the ones u would use, you can also use properties and subs.

Do this make any sense to you?

Thanks,

Loren

Author

Commented:
so, these are the steps:

1) I create a file.asp
2) write a function like this:

// What I only need is to add "Public" to it and classe name

Classe MyClass1
    Function Even(num)
       if (num MOD 2) = 1 Then
          Even = False
       else
          Even = True
       end If
   End Function
End class

3) Use include as you explained to me. At the bottom of my asp file.

<!--#include file ="Library.asp"-->

Is It?
Joachim CarreinSr. Software Developer
Commented:
you don't even need the class
when including, you can just call the function/sub(you even don't need "call")

like this:

file.asp
------------------------------------------------------------------------------------------------------------
sub test()
  response.write("hello world!")
end sub

function test2()
  test2 = "Hello world2!"
end sub
------------------------------------------------------------------------------------------------------------


page.asp
------------------------------------------------------------------------------------------------------------
<!--#include file=test2.asp-->
<%
test
%>
<br><br>
<%
Response.Write(test2)
%>
------------------------------------------------------------------------------------------------------------

Author

Commented:
Well, what is the difference between class and a asp file with functions?
Commented:
I use script classes only for more complicated solutions. For example I have seperate script classes that handle (pure-script) fileupload, binary files, semi-automated database actions, error-logging, recursive tables and some more.

I store each class in a seperate file that I include in pages when needed.

Also I have a number of files with generic and relatively simple functions (not classes). One with a number of functions I use very often, others for working with the FileSystemObject, for creating forms from data in a database, for dealing with XML. Only the file with the very-often-used functions is uincluded always, the rest only when needed.


Some differences between classes and functions

* When using a class, you need to create an object first before you can use its functions. When nothing complicated is being done: use a function.
<%
' using a class
Set MyClass = new FunctionsClass
SomeVar = MyClass.SomeMethod(var1, var2)

' using a function
SomeVar = SomeMethod(var1, var2)
%>

* A class has methods and properties, and sometimes it is useful to re-use the same object. It is nice that the properties assigned on first use and which are identical on the second use, don't need to be given the second time. A function will need all parameters passed to it every time you use it.
(Remember that an object based on a script class is always destroyed at the end of the ASP-page, so the second use of the same object must always be done in the same ASP-page)

<%
' using a class
Set MyClass = new FunctionsClass
MyClass.PropertyOne = 24
MyClass.PropertyTwo = 4
SomeVar1 = MyClass.MuliplyPropertyOneAndTwo
SomeVar2 = MyClass.DividePropertyOneWithTwo


' using functions
SomeNumberOne = 24
SomeNumberTwo = 4
SomeVar1 = Multiply(SomeNumberOne, SomeNumberTwo)
SomeVar2 = Divide(SomeNumberOne, SomeNumberTwo)

%>





Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.