Hi,
I have been using ASP for over 12 years and never used a class. Today i looked for tutorials and came across this one, it's a really well documented article.
Problem is when you copy the example it throughs up an error, which is stumping me. Could someone that understands classes just point out whats breaking it please.
There are two pages. to test the example.
The line error is:
Microsoft VBScript compilation error '800a03f2'
Expected identifier
/Greeting.asp, line 4
Public Class Greeting
-------^
PAGE 1 - Greeting.asp
PAGE TWO: Index.asp
I have been using ASP for over 12 years and never used a class. Today i looked for tutorials and came across this one, it's a really well documented article.
Problem is when you copy the example it throughs up an error, which is stumping me. Could someone that understands classes just point out whats breaking it please.
There are two pages. to test the example.
The line error is:
Microsoft VBScript compilation error '800a03f2'
Expected identifier
/Greeting.asp, line 4
Public Class Greeting
-------^
PAGE 1 - Greeting.asp
Code:
<%
Dim Greeting
Public Class Greeting
'Private member variable accessible only
'to the class Private m_sGreeting
'Accessor method, controlled aliased
'READ access to your class variable
Public Property Get Message()
Message = m_sGreeting
End Property
'Accessor method, controlled aliased
'WRITE access to your class variable
Public Property Set Message(sMsg)
m_sGreeting = sMsg
End Property
'The constructor, initialization for
'your object
Private Sub Class_Initialize()
m_sGreeting = "Hello world!??"
End Sub
'Public class method, something this
'class can do for you.
Public Sub Greet()
Response.Write m_sGreeting
End Sub
'Cleaning up.
'Unhand that RAM you hog !
'There’s nothing to clean up in this
'small class, so this is here for
'demonstration onlyPrivate
Sub Class_Terminate()
End Sub
End Class
%>
PAGE TWO: Index.asp
Code:
<%@ Language=VBScript %>
<%Option Explicit
'This next bit is an SSI (server Side Include) It means put here
'the contents of Greeting.asp as if it were part of the code
'in this page.
%>
<!-- #include file="Greeting.asp" -->
<%
Dim oGreeting
'Instantiate an object of type Greeting
Set oGreeting = New Greeting
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<P>
<%
'Call the Greet method
oGreeting.Greet
'Destroy our object
Set oGreeting = nothing
%>
</P>
</BODY>
</HTML>