Solved

Differences between a VBScript Class and using includes

Posted on 2002-04-06
3
716 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

776 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