Classic ASP class constructors with parameters

John Avis by | June 8, 2016 | Classic ASP

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.
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

Classic ASP

Sending email using Amazon SES with Classic ASP

by John Avis | March 21, 2017

I recently needed to change a client's website to send emails using Amazon SES and encountered a few issues.


Classic ASP

Classic ASP cookie with no name hacking attack causing error 80004005

by John Avis | July 31, 2015

As of July 2015, many of my Classic ASP websites have started logging strange errors, either 80004005 or not reporting any error code at all.


Classic ASP

Classic ASP functions for database queries and SQL injection protection

by John Avis | July 28, 2014

If writing database queries in SQL in Classic ASP for SQL Server, rather than using ADO or parameterised queries, you can use these functions to correctly format your data and protect against SQL injection.

Comments

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

Leave a Comment
Tags
ASP.NET Html Forms ASP.NET MVC ASP.NET Web Forms ASP.NET Web Pages Bootstrap C# Classic ASP Cool Websites Databases eBay and PayPal Electrical Repairs General Hardware HTML/CSS Jquery/Javascript Media Center Mobile Phones Responsive Web Design SEO and Social Networking Web Design Web Development Web Security web+db Website Hosting Windows XP

About me

...mostly about web development and programming, with a little bit of anything else related to the Internet, computers and technology.

Subscribe

Get the latest posts delivered to your inbox.