Classic ASP class constructors with parameters

johna by | June 8, 2016 | Classic ASP Web Development

Although probably no one cares about Classic ASP, except those who still need to support it, I was refreshing my memory today on how to use classes in Classic ASP and found a couple of options for simulating constructors with parameters.

We start with a simple class and add a default function that returns the current instance:

Class MyClass
Private m_myvalue

Public Default Function Init(myvalue)
m_myvalue= myvalue

Set Init = Me
End Function

Public Property Get MyValue
MyValue = m_myvalue
End Property
End Class

Then we can create an instance of our class with a faux constructor, like this...

Set myobject = (New MyClass)(123)

...or, if you prefer, this...

Set myobject = New MyClass.Init(123)

Sources: www.visualbasicscript.com/Initializing-a-Class-with-parameters-m76239.aspx and brendangadd.blogspot.com.au/2011/06/constructors-in-asp-classic.html.

Related Posts

Web Development

How to set up a debugging using the Turnkey Linux LAMP stack and VS Code

by johna | December 19, 2023
The second part in my guide to setting up a website and database using the Turnkey Linux LAMP stack.

Website Hosting Web Development

How to set up a website and database using the Turnkey Linux LAMP stack

by johna | November 18, 2023
If you need to host your own website for the purposes of web development, Turnkey Linux LAMP Stack is an easy to install all-in-one solution that you can set up on a spare computer or a VM (Virtual Machine).

Web Development

Intermittent "Unable to read data from the transport connection: net_io_connectionclosed" errors

by johna | May 6, 2020
If you are having intermittent problems sending email in .NET using System.Net.Mail consider switching libraries.

Comments

There are no comments yet. Be the first to leave a comment!

Leave a Comment

About

...random postings about web development and programming, Internet, computers and electronics topics.

I recommend ASPnix for web hosting and Crazy Domains for domain registration.

Subscribe

Get the latest posts delivered to your inbox.