Geekpedia Tutorials Home

Building a C# Chat Client and Server

Building a C# Chat Client and ServerA step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.

in C# Programming Tutorials

Getting Hard Drive Information

Getting Hard Drive InformationA C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.

in C# Programming Tutorials

UPS Shipping Calculator

UPS Shipping CalculatorThis tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.

in PHP Programming Tutorials

Create Your Own Rich Text Editor

Create Your Own Rich Text EditorCreating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.

in JavaScript Programming Tutorials
Search
Tutorials
Programming Tutorials
IT Jobs
From CareerBuilder

Objects in ASP

How to create a custom object in ASP (done just now for a mate in need...).

On Monday, September 27th 2004 at 06:46 PM
By Matt W (View Profile)
****-   (Rated 3.8 with 10 votes)
Contextual Ads
More ASP Resources
Advertisement


<%
Option Explicit

'
' Class Example just for Neil... <-- a geezer new to ASP
'=======================================
' Imagine an object as a mini program in its own right that gives
' a larger parent program a controlled amount of access.
'
' Basically any code you do inside an object won't affect the rest
' of your code other than by the rules you set.  =O)
'
' Good for security, re-useability and ease of use in the medium/
' long-term of a project.  Basic standard includes that contains 
' loads of function/sub code snippets become cumbersome and messy 
' over time.  Objects solve that issue.
'
' I like keeping 1 object per include... =)  makes it easy to just
' include what I need... =)
'
'
Class MyClass
    '
    '-------------------------------
    ' Properties (local variables)
    '  - You can make them public, but that is insecure and stupid.
    '
    Private i_MyData    ' Used internally, but given secured access
                        ' via Property Let/Get
    Private s_String    ' Only used internally
    '
    '-------------------------------
    ' Property Accessots
    ' - These are the rules for i_MyData (Let/Get)
    '
    Public Property Let MyData(valueIn)
        '
        ' valueIn is the data given to property (as in... property = valueIn)
        '
        If valueIn>777 Then valueIn = 777
        If valueIn<111 Then valueIn = 111
        '
        i_MyData = valueIn
    End Property
    Public Property Get MyData
        '
        ' This allows data to be retrived [as in... Response.write(myObj.MyData) ]
        '
        MyData = i_MyData
    End Property
    
    '
    '-------------------------------
    ' Constructors/Deconstructors/
    '  - These fire when creating/destroying object
    '
    Private Sub Class_Initialize
        '
        ' Use this to set local variables...
        '
        i_MyData = 777 ' Monkeys gone to heaven...
        s_String = "No data here... "
        '
        Response.Write("myClass has started<br>")
    End Sub
    '
    Private Sub Class_Terminate
        '
        ' Use this to clean up
        '
        Response.Write("myClass has stopped<br>")
    End Sub
    
    '-------------------------------
    ' Methods
    '
    Public Sub DoSomething()
        '
        ' internal Sub (called a method)
        '
        Response.Write(s_String & i_MyData & "<br>")
    End Sub
    
    Public Function NonsenseMaths(NumberIn)
        '
        ' internal Function (also called a method)
        '
        If NumberIn>20 Then NumberIn = 20
        If NumberIn<5  Then NumberIn = 5
        '
        NonsenseMaths = i_MyData * NumberIn
    End Function
End Class
'
'================================================================
'
' Now for use...
'
Dim sStick ' This will hold our new object

Set sStick = New MyClass
    Response.write(sStick.MyData)
    Response.write("<br>")
    sStick.MyData = 666 ' the devil (booo!)
    Response.write(sStick.MyData)
    Response.write("<br>")
    sStick.DoSomething()
    Response.write(sStick.NonsenseMaths(9))
    Response.write("<br>")
Set sStick = Nothing
%>
Digg Digg It!     Del.icio.us Del.icio.us     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this tutorial
Comment Current Comments
by gopi on Wednesday, June 14th 2006 at 11:21 AM

Very good for begineers like me!


Comment Comment on this tutorial
Name: Email:
Message:
Comment Related Tutorials
There are no related tutorials.

Comment Related Source Code
There is no related source code.

Jobs ASP Job Search
My skills include:
Enter a City:

Select a State:


Advanced Search >>
Sponsors
Discover Geekpedia

Other Resources