www.webdeveloper.com
Results 1 to 4 of 4

Thread: Inheritance/expanding a class with ASP VBScript

  1. #1
    Join Date
    Nov 2006
    Location
    London, UK
    Posts
    6

    Inheritance/expanding a class with ASP VBScript

    Hi there,

    does anybody know how to implement some sort of class inheritance, with classic ASP using VB Script?

    Using JScript you can use a syntax like this

    Code:
    class ExampleClass extends DerivedClass
    and ExampleClass will inherit from DerivedClass as a result.

    Is there any way of doing something like this with VBScript?

    Many thanks in advance,
    S.

  2. #2
    Join Date
    Jul 2005
    Location
    Tangerang, Indonesia
    Posts
    171
    as long as i read vbscript documentation, i never see any operator/statement for class inheritance. unfortunately there is no extends statement in vbscript.
    and unfortunately (too) there is no support for inheritance in vbscript

    however we still can "simulating" an inheritance by delegating derived class to extended class. but we need to rewrite all properties and methods of derived class.

    PHP Code:
    <%
    Class 
    DerivedClass
    private m_propA
    Sub Class_Initialize 
      m_propA 
    ""
    End Sub
    public property let PropA (data)
      
    m_propA data
    end property
    public property get PropA ()
      
    PropA m_propA
    end property
    public sub MethodA(data1,data2)
      
    response.write "This is only sample for VBScript Inheritance"
      
    response.write "<br>"
      
    response.write "Your data is : <br>"
      
    response.write "data 1 = " data1 ", data 2 = " data2
      response
    .write "<br>"
      
    response.write "and your PropA value is: " Me.PropA
    end sub
    End 
    Class

    Class 
    ExampleClass
      
    Private dc 'As New DerivedClass
      Sub Class_Initialize 
        Set dc = New DerivedClass
      End Sub
      Sub Class_Terminate
        Set dc = Nothing
      End Sub
      ' 
    Begin Delegate Code
      
    public property let PropA (data)
        
    dc.PropA  data
      end property
      
    public property get PropA ()
        
    PropA dc.PropA 
      end property
      
    public sub MethodA (data1data2)
        
    dc.MethodA data1,data2
      end sub
      
    'End Delegate Code

      Public Sub ExClassMethod()
        Response.Write "This is from ExampleClass"
      End Sub
    End Class

    dim ex
    set ex = new ExampleClass
    ex.PropA  = "Testing"
    ex.MethodA  "Data Satu","Data Dua"
    response.write "<br>"
    ex.ExClassMethod

    %> 

  3. #3
    Join Date
    Nov 2006
    Location
    London, UK
    Posts
    6
    Hi.

    I had solved that somehow else already, but I was still looking forward to hearing of any possible more direct solutions, just out of curiosity.

    Thanks anyway; it's a shame you can't do that straight away with vbscript, but at the same time am glad to have given it up long ago, at least for most things.

  4. #4
    Join Date
    Feb 2003
    Posts
    2,745
    shouldn't need to rewrite methods unless overriding them.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles