Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP Classes 3

Status
Not open for further replies.

craigward

Programmer
Nov 13, 2007
230
GB
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

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>
 
Try removing the 'Public' part.

Change:
[tt]Public Class Greeting[/tt]

To:
[tt]Class Greeting[/tt]

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Take out the dim line too.
[tt] [red]'[/red]Dim Greeting[/tt]
 
Also make sure this is not an artifact.
>'to the class Private m_sGreeting
[tt]'to the class
Private m_sGreeting[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top