Solved

Differences between a VBScript Class and using includes

Posted on 2002-04-06
3
714 Views
Last Modified: 2013-11-18
Is there any difference regarding performance, etc. in using a VBScript class file over an include file in an ASP page?
0
Comment
Question by:wsteph
  • 2
3 Comments
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 6923379
I am not familiar with the use of a "VBscript class file", I am afraid you have to explain that one. (I found nothing relevant in MSDN when searching for it).

The SSI include is quite a basic function that uses very little resources. I once made a test where I had one file include hundreds of other files, and the execution time for this was not even noticable.

The concept of classes is quite different from including files, so the answer to your question must be that it depends very much on what you would be using it for.
0
 

Author Comment

by:wsteph
ID: 6923424
A VBScript class file is used in practically the same way a class in a dll would be. For instance say I have a file called methods.vbs and have the following code in that file:

<%
Class MyClassMethods
  Private Sub ConnectToDatabase()
    ...Code to connect to db
  End Sub

  Public Function GetRecords()
    ...Code to return db data to ASP page
  End Function
End Class
%>

I can call the methods in the script file much like I would call the methods in a dll from the ASP page like so:

<% @Language=VBScript %>
<!-- #include file="classes/class.cls" -->
<%
  Dim strHoldReturnData
  Dim objASPClass
  Set objASPClass = New MyClassMethods
  strHoldReturnData = objASPclass.GetRecords
  Set ObjASPClass = Nothing
%>

I was just wondering if there were any substantial differences between using this approach to encapsulate methods or just using a plain old include file that contains the methods. As you found out, Microsoft doesn't provide much information on this topic.
0
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 25 total points
ID: 6923933
Oh, you mean just a plain simple include file containing a VBScript class definition. :)

I have to disagree that the class file is used even remotely the same way as a dll. The class file is simply a plain text file that is added to the source before the ASP parser gets it's hands on it. To ASP it looks like a single file. Just because the include file has a special name or contains code for a class definition, there is nothing special with it; there is no added functionality over a plain include file.

Well, lets get to the point: As you use the same method for including functions and classes, there is no difference there. The only difference is encapsulating the code in a class. The overhead for this is not very much, though, it will add about a millisecond or two to the execution time of your code.

Usually objects is used to hold some kind of data. If your functions doesn't share any data, there is no reason to put them together in a class.

If you find it useful to construct a class, you should definitely do so, but not for the sole purpose of grouping some functions together.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

746 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now