Emulating the "this" pointer in ASP/VBScript

Posted on 2006-06-08
Last Modified: 2008-02-26
I am seeking comments/ideas on how I might emulate the "this" pointer in ASP/VBScript. The "this" pointer is available in many object oriented languages including C++, Java and PHP, but is not available in ASP/VBScript.

Question: If you need a "this" pointer in ASP/VBScript how would you implement it?

Thank you.

Note: If you don't know what a "this" pointer is, please do not reply. Thanks!
Question by:dangould
    LVL 52

    Expert Comment

    by:Carl Tawn
    In what context ? Are you using classes in your VBScript ?

    Author Comment

    Yes, I should have mentioned that this is a class/object based design.

    Thank you for the clarification question.
    LVL 6

    Expert Comment

    ASP has very poor support for object-oriented programming. There is no support for the 'this' pointer within an object method. ASP does not provide functionality for pointers anyways, so this makes sense. My suggestion, do as much of your programming in C++, put it in a COM object, and then implement it in ASP.

    Author Comment

    Unfortunately, my application has to be 100% script based, for portability reasons.

    I agree that VBScript support for classes is limited, but what's there actually works pretty well. You can pass an object handle through a subroutine call, store it in an array or in a dictionary object. That's pretty flexible for a scripting language.

    I've been experimenting with emulating the "this" pointer like this...

       Set oClass = New ClassName
       ClassName.this = oClass

    Where "this" is a property defined withing clsClassName. You can then use inside a class definition more or less like in C++.
    LVL 25

    Accepted Solution

    Isn't Me supported in VBScript?  Yeah.  It is.

    class Test

       dim myVar

       sub myMethod
            dim myVar
          Me.myVar = "hello"
           myVar = "local variable"
       end sub

    end class

    dim o1
    set o1 = new Test

    response.write o1.myVar

    Author Comment

    clockwatcher: You are soooo right, and I have confirmed that your sample code works in my case. Since reading your post, I found the following brief description on using the "Me" pointer in VBScript.

    Thank you for your assistance and excellent code sample.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Suggested Solutions

    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…
    I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    761 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

    7 Experts available now in Live!

    Get 1:1 Help Now