Sideway BICK BlogSideway BICK BLOG from Sideway

A Sideway to Sideway Home

Link:http://output.to/sideway/default.asp?qno=180500005

Script, Scripting Language, VBScript elements, Server-Side VBScript Class Object

VBScript Class Object

Class Object is a special VBScript Object created by using the Class statement. In other word, Class Object is an Object of user-defined type. There is no predefined Class Method, Class Property, and Class Collection for the Class Object. But, the Class Object provides access to the two events of the Class Object, namely Initialize Event and Terminate Event.

Class Object

last updated 12/6/2017

is to provide a class of user-defined types Object created by the Class statement.

Syntax

Class classname
   statements
End Class
Set classobjvar = New classname

Argument

Class statement../sideway/default.asp?qno=180400030 Set statement../sideway/default.asp?qno=180400026

Remarks

  • an user-defined types Object created by using the Class statement and a new instance of Object reference is assigned by Set statement.
  • Class Object is a special user-defined Object created or declared by using the Class statement.
  • A Class Object cannot be declared explicitly without the using of the Class statement.
  • A Set statement can then be used to create and assign a New instance of the Class Object to an Object variable as an ordinary Object.
  • A Class Object provides access to the Initialize Event and Terminate Event of the Class Object.

Requirement

5

Class Methods

last updated 12/6/2017

No Method is predefined for the Class Object. However, user-defined Methods can be constructed by traditional procedure statements, for example, Sub and Function Statements. Dot notation is used to access a Class Method inside a Class Object, for example, classobjectvariable.methodname.

Syntax

[Public [Default]  | Private] Sub procname [(arglist)] 
   [statements]
   [Exit Sub]
   [statements]
End Sub
[Public [Default] | Private] Function procname [(arglist)]
   [statements]
   [name = expression]
   [Exit Function] 
   [statements]
   [name = expression]
End Function
classobjvar.procname[(arglist)]
arglist:  [ByVal | ByRef] varname[(…)],[ByVal | ByRef] varname[(…)],…

Argument

Sub statement../sideway/default.asp?qno=180400030 Function statement../sideway/default.asp?qno=180400030

Remarks

  • A Method is an embedded Object related function or procedure in the Object.
  • Method procedures are always created and contained inside an Object in form of the child of an Object.
  • A Method can be Private that can only be accessed by things inside the Object or Public that can also be accessed by things outside the Object.
  • Traditional procedure statements, Sub and Function Statements, can be used to construct Methods of a Class Object.

Class Properties

last updated 12/7/2017

No Property is predefined for the Class Object. However, user-defined Properties can be constructed by Property related statements, for example, Property Get, Property Let, and Property Set Statements. Dot notation is used to access a Class Property inside a Class Object, for example, classobjectvariable.propertydname.

Syntax

[Public [Default] | Private] Property Get propname [(arglist)]
   [statements]
   [[Set] name = expression]
   [Exit Property] 
   [statements]
   [[Set] name = expression]
End Property
[Public | Private] Property Let propname ([arglist,] value)
   [statements]
   [Exit Property] 
   [statements]
End Property
[Public | Private] Property Set propname([arglist,] reference)
   [statements]
   [Exit Property] 
   [statements]
End Property
classobjvar.propname[(arglist)]
arglist:  [ByVal | ByRef] varname[(…)],[ByVal | ByRef] varname[(…)],…

Argument

Property Get statement../sideway/default.asp?qno=180400030 Property Let statement../sideway/default.asp?qno=180400030 Property Set statement../sideway/default.asp?qno=180400030

Remarks

  • A Property is an embedded Object related thing in the Object.
  • Property variables are always created and contained inside an Object in form of the child of an Object.
  • In general, a Property is used to constain a thing of an object instead of used as a variable to contain a value.
  • In fact, a variable can still be used inside a Class Object as usual.

Class Collections

last updated 12/7/2017

No Collection is predefined for the Class Object. However, user-defined Collections can be constructed by making use of Collection related Objects, for example, Scripting.Dictionary, System.Collections.ArrayList, System.Collections.SortedList, System.Collections.Stack, and System.Collections.Queue.

Remarks

  • A Collection is a set of ordered things that do not have to be of the same data type.
  • A Collection is a flexiable array with the index number of an item element is usually updated when an item element is added or removed.
  • The indexed number of the elements of a Collection usually begins at 1. However the indexed number of a Collection Array may begins at 0.

Class Event

last updated 12/7/2017

Two Events are predefined for the Class Object. The two Events are the Initialize Event and Terminate Event of the associated Class Object. The two Events are Event actions used to fire the associated routines accordingly.

Remarks

  • In general, an Event is a trigger action due to the status change caused by user actions, applications or the operating system.
  • Sometimes, an Event is also refered to an Event response, that is an associated function or procedure of which triggered by an Event.
  • The Initialize Event occurs when an instance of the associated Class is created.
  • The Terminate Event occurs when an instance of the associated Class is terminated.
  • The two build-in Events of Class Object using the built-in mechanism to hook up Event to VBScript through a naming convention.
  • The Initialize Event will trigger the Sub Class_Initialize procedure of the associated Class Object.
  • The Terminate Event will trigger the Sub Class_Terminate procedure of the associated Class Object.

Class Event Response

last updated 12/7/2017

Two Event responses are predefined for the Class Object. The two Event responses are the Class_Initialize subroutine and Class_Terminate subroutine inside the associated Class Object. The two Event subroutines are Event responses used to response the associated fired Event calls accordingly.

Remarks

  • Sometimes an Event response is also called to an Event.
  • An Event response is an associated function or procedure of which triggered by an Event.
  • The Initialize Event response is called when an instance of the associated Class is created.
  • The Terminate Event response is called when an instance of the associated Class is terminated.
  • The two build-in Event responses of Class Object uses the built-in mechanism to hook up Event to VBScript through naming convention.
  • The Initialize Event will trigger the Sub Class_Initialize procedure of the associated Class Object.
  • The Terminate Event will trigger the Sub Class_Terminate procedure of the associated Class Object.

Examples

Examples of Class Object

ASP VbScript Command:
<script runat="server" language="VBScript">
Dim vars,strs,cmda
cmda=array("d.xa","d.xb","e")
Dim ucnt,tmp,i:ucnt=UBound(cmda):If var=1 Then:tmp="":Else:tmp="<b>vars</b>":End If:For i=0 to ucnt:tmp=tmp&"<b>"&rmv_ctrl(cmda(i))&", TypeName</b>":Next:Response.Write "Results on Microsoft Windows 8.1 Pro x64, Microsoft-IIS/8.5, VBScript Version 5.8 of page /internet/users/sideblog/default.asp<br />"&"<i>"&tmp&"</i>"
Function dsp_x:Dim tmp_a,tmp_b,i:If varx=0  Then:Execute vars:End If:If var=1 Then:tmp_a="":Else:tmp_a=rmv_ctrl(vars):End If:For i=0 to ucnt:tmp_b=cmd_b(cmda(i)):if i/2=fix(i/2) Then:tmp_b="<b>"&tmp_b&"</b>":End If:tmp_a=tmp_a&tmp_b:Next:Response.Write "<i>"&tmp_a&"</i>":End Function
Function rmv_ctrl(blk_str):Select Case blk_str:Case chr(0):blk_str="NUL":Case chr(1):blk_str="SOH":Case chr(2):blk_str="STX":Case chr(3):blk_str="ETX":Case chr(4):blk_str="EOT":Case chr(5):blk_str="ENQ":Case chr(6):blk_str="ACK":Case chr(7):blk_str="BEL":Case chr(8):blk_str="BS":Case chr(9):blk_str="HT":Case chr(10):blk_str="LF":Case chr(11):blk_str="VT":Case chr(12):blk_str="FF":Case chr(13):blk_str="CR":Case chr(14):blk_str="SO":Case chr(15):blk_str="SI":Case chr(16):blk_str="DLE":Case chr(17):blk_str="DC1":Case chr(18):blk_str="DC2":Case chr(19):blk_str="DC3":Case chr(20):blk_str="DC4":Case chr(21):blk_str="NAK":Case chr(22):blk_str="SYN":Case chr(23):blk_str="ETB":Case chr(24):blk_str="CAN":Case chr(25):blk_str="EM":Case chr(26):blk_str="SUB":Case chr(27):blk_str="ESC":Case chr(28):blk_str="FS":Case chr(29):blk_str="GS":Case chr(30):blk_str="RS":Case chr(31):blk_str="US":Case chr(127):blk_str="DEL":End Select:rmv_ctrl=blk_str:If IsNull(blk_str) OR IsEmpty(Blk_str) OR blk_str="" OR IsNumeric(Blk_str) Then:Else:rmv_ctrl=Replace(Replace(Replace(Replace(Replace(blk_str,"&","&amp;"),"  "," &nbsp;"),"""","&quot;"),"<","&lt;"),">","&gt;"): End If :End Function
Function cmd_b(blk_str):cmd_b="["&cmd_x(blk_str)&"], "&cmd_x("TypeName("&blk_str&")"):End Function
Function cmd_x(blk_str):On Error Resume Next:Dim xans, tmp:xans="":tmp="":execute "xans="&blk_str:If Err.Number <> 0  Then:xans=cmd_x("TypeName("&blk_str&")"):Select Case xans:Case 9::Case Else:xans="error":End Select:End If:If IsArray(xans)=False Then:cmd_x=rmv_ctrl(xans): Else:tmp=lst_arry(xans):cmd_x=trim(tmp):End If:End Function
Function lst_arry(blk_str):Dim tmp,i,q:q="""":tmp="":For i=0 to UBound(blk_str):if VarType(blk_str(i))>1 And VarType(blk_str(i))<6 Then:q="'":End If:tmp=tmp&" "&q&rmv_ctrl(blk_str(i))&q:Next:lst_arry=trim(tmp):End Function

vars="e=9:Class xclass:Public e:Private a:Private b:Private Sub Class_Initialize:a = """":e = 0:b = 0:End Sub:Public Property Get xa:xa = a:End Property:Public Property Let xa(stra):a = stra:End Property:Public Property Get xb:xb = b:End Property:Public Sub Incb(numb):b=b+numb:End Sub:Public Function Incfunc(numb):b=b+numb:Incfunc=999:End Function:End Class:set d=New xclass":dsp_x
vars="d.xa=""stra"":e=d.xa":dsp_x
vars="d.incb(3)":dsp_x
vars="d.incb(3):e=d.Incfunc(1)":dsp_x
</script>
HTML Web Page In-line Output:
Results on Microsoft Windows 8.1 Pro x64, Microsoft-IIS/8.5, VBScript Version 5.8 of page /internet/users/sideblog/default.asp
varsd.xa, TypeNamed.xb, TypeNamee, TypeNamee=9:Class xclass:Public e:Private a:Private b:Private Sub Class_Initialize:a = "":e = 0:b = 0:End Sub:Public Property Get xa:xa = a:End Property:Public Property Let xa(stra):a = stra:End Property:Public Property Get xb:xb = b:End Property:Public Sub Incb(numb):b=b+numb:End Sub:Public Function Incfunc(numb):b=b+numb:Incfunc=999:End Function:End Class:set d=New xclass[], String[0], Integer[9], Integerd.xa="stra":e=d.xa[stra], String[0], Integer[stra], Stringd.incb(3)[stra], String[3], Integer[stra], Stringd.incb(3):e=d.Incfunc(1)[stra], String[7], Integer[999], Integer

Sideway BICK Blog

05/05


Copyright © 2000-2020 Sideway . All rights reserved Disclaimerslast modified on 26 January 2013