Questions on class definition in ASP.

L

Laser Lu

Can we define events in a class when coding using VBScript in ASP?
I still have the second question, even if the answer is positive. That is
whether the two standard events of a calss module in VB, "Class_Initialize"
and "Class_Terminate", is still availabe in VBScript?
If not, then how to initialize an instance of a class automatically when it
is created?
 
L

Laser Lu

By the way, another question, how to set a property or method as the default
property or method of a class in VBScript?
Any reply would be appreciated!
 
D

dlbjr

Example:

<SCRIPT language="vbscript" runat="server">
Class StringMaker
Private marrayData
Private mintGrowthRate
Private mintItemCount
Private mstrJoint

Private Sub Class_Initialize()
mintGrowthRate = 100
mintItemCount = 0
mstrJoint = ""
ReDim marrayData(mintGrowthRate)
End Sub

Private Sub Class_Terminate()
Erase marrayData
End Sub

Public Property Let Joint(strData)
mstrJoint = strData & ""
End Property

Public Property Let GrowthRate(strData)
strData = Trim(strData)
If IsNumeric(strData) Then
strData = Abs(CDbl(strData))
If strData > 0 Then
mintGrowthRate = strData
ReDim marrayData(mintGrowthRate)
End If
End If
End Property

Public Sub Append(strData)
strData = Trim(strData)
If Len(strData) > 0 Then
If mintItemCount > UBound(marrayData) Then
ReDim Preserve marrayData(UBound(marrayData) + mintGrowthRate)
End If
marrayData(mintItemCount) = strData
mintItemCount = mintItemCount + 1
End If
End Sub

Public Sub Reset
Erase marrayData
Class_Initialize
End Sub

Public Function Result()
Redim Preserve marrayData(mintItemCount)
Result = Join(marrayData, mstrJoint)
End Function

Public Function ToString()
Redim Preserve marrayData(mintItemCount)
ToString = Join(marrayData, mstrJoint)
End Function
End Class
</SCRIPT>
 
L

Laser Lu

Deart dlbjr,
Thanks very much for your code example!
By the way, is it possible to define a default property or method in a Class
in VBScript?
 
D

dlbjr

Don't believe so. I have never really set default properties when using
vbScript classes as in VB.

-dlbjr

Discerning resolutions for the alms
 
H

Harag

yes it is.

put the word DEFAULT before the function/property word and after the
public word.

eg

PUBLIC Default FUNCTION MyFunctionName (ByVal iParam)


HTH
Al.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,817
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top