Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to create a library asp of functions and procedure

Posted on 2006-03-21
7
Medium Priority
?
295 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
0
Comment
Question by:hidrau
7 Comments
 
LVL 4

Assisted Solution

by:LTY83
LTY83 earned 400 total points
ID: 16251741
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



0
 
LVL 1

Author Comment

by:hidrau
ID: 16251849
I make a file.asp with this lines:

Class Example

Public Function ExampleFunction()
DoSomething
End Function

End Class

is it?
0
 
LVL 4

Expert Comment

by:LTY83
ID: 16251881
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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:hidrau
ID: 16251941
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?
0
 
LVL 4

Assisted Solution

by:Joachim Carrein
Joachim Carrein earned 400 total points
ID: 16255479
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)
%>
------------------------------------------------------------------------------------------------------------
0
 
LVL 1

Author Comment

by:hidrau
ID: 16256313
Well, what is the difference between class and a asp file with functions?
0
 
LVL 28

Accepted Solution

by:
sybe earned 1200 total points
ID: 16261580
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)

%>





0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question