1 VBScript Session 17. 2 What we learn last session?
-
Upload
molly-jackson -
Category
Documents
-
view
229 -
download
1
Transcript of 1 VBScript Session 17. 2 What we learn last session?
![Page 1: 1 VBScript Session 17. 2 What we learn last session?](https://reader033.fdocuments.net/reader033/viewer/2022061304/5513deb655034679748b5340/html5/thumbnails/1.jpg)
1
VBScript
Session 17
![Page 2: 1 VBScript Session 17. 2 What we learn last session?](https://reader033.fdocuments.net/reader033/viewer/2022061304/5513deb655034679748b5340/html5/thumbnails/2.jpg)
2
What we learn last session?
![Page 3: 1 VBScript Session 17. 2 What we learn last session?](https://reader033.fdocuments.net/reader033/viewer/2022061304/5513deb655034679748b5340/html5/thumbnails/3.jpg)
3
Subjects for session 17
Class object. Class statement.
Property Let. Property Get. Property Set. Initialize event. Terminate event.
Inline classes. Registering your COM classes.
![Page 4: 1 VBScript Session 17. 2 What we learn last session?](https://reader033.fdocuments.net/reader033/viewer/2022061304/5513deb655034679748b5340/html5/thumbnails/4.jpg)
4
Classes in VBScriptClass Object
The object created using the Class statement. Provides access to the events of the class. You cannot explicitly declare a variable to be of
type Class. In the VBScript context, the term "class object"
refers to any object defined using the VBScript Class statement.
Dim X Set X = New classname
![Page 5: 1 VBScript Session 17. 2 What we learn last session?](https://reader033.fdocuments.net/reader033/viewer/2022061304/5513deb655034679748b5340/html5/thumbnails/5.jpg)
5
Classes in VBScriptClass Statement
Declares the name of a class, as well as a definition of the variables, properties, and methods that comprise the class.
SyntaxClass name statements
End Class
![Page 6: 1 VBScript Session 17. 2 What we learn last session?](https://reader033.fdocuments.net/reader033/viewer/2022061304/5513deb655034679748b5340/html5/thumbnails/6.jpg)
6
Classes in VBScriptClass Statement
Within a Class block, members are declared as either Private or Public using the appropriate declaration statements.
Anything declared as Private is visible only within the Class block. Anything declared as Public is visible within the Class block, as well
as by code outside the Class block. Anything not explicitly declared as either Private or Public is Public
by default. Procedures (either Sub or Function) declared Public within the class
block become methods of the class. Public variables serve as properties of the class, as do properties
explicitly declared using Property Get, Property Let, and Property Set.
Default properties and methods for the class are specified in their declarations using the Default keyword.
![Page 7: 1 VBScript Session 17. 2 What we learn last session?](https://reader033.fdocuments.net/reader033/viewer/2022061304/5513deb655034679748b5340/html5/thumbnails/7.jpg)
7
Classes in VBScriptGet Property Statement
Declares, in a Class block, the name, arguments, and code that form the body of a Property procedure that gets (returns) the value of a property.
Syntax
[Public [Default] | Private] Property Get name [(arglist)] [statements] [[Set] name = expression] [Exit Property] [statements]
End Property
![Page 8: 1 VBScript Session 17. 2 What we learn last session?](https://reader033.fdocuments.net/reader033/viewer/2022061304/5513deb655034679748b5340/html5/thumbnails/8.jpg)
8
Classes in VBScriptGet Property Statement
If not explicitly specified using either Public or Private, Property Get procedures are public by default, that is, they are visible to all other procedures in your script.
The value of local variables in a Property Get procedure is not preserved between calls to the procedure.
You can't define a Property Get procedure inside any other procedure.
The Exit Property statement causes an immediate exit from a Property Get procedure.
Property Get procedure is a separate procedure that can take arguments, perform a series of statements, and change the value of its arguments.
![Page 9: 1 VBScript Session 17. 2 What we learn last session?](https://reader033.fdocuments.net/reader033/viewer/2022061304/5513deb655034679748b5340/html5/thumbnails/9.jpg)
9
Classes in VBScriptLet Property Statement
Declares, in a Class block, the name, arguments, and code that form the body of a Property procedure that assigns (sets) the value of a property.
Syntax
[Public [Default] | Private] Property Let name ([arglist,] value) [statements] [[Set] name = expression] [Exit Property] [statements]
End Property
![Page 10: 1 VBScript Session 17. 2 What we learn last session?](https://reader033.fdocuments.net/reader033/viewer/2022061304/5513deb655034679748b5340/html5/thumbnails/10.jpg)
10
Classes in VBScriptLet Property Statement
If not explicitly specified using either Public or Private, Property Let procedures are public by default, that is, they are visible to all other procedures in your script.
The value of local variables in a Property Let procedure is not preserved between calls to the procedure.
You can't define a Property Let procedure inside any other procedure.
The Exit Property statement causes an immediate exit from a Property Let procedure.
Every Property Let statement must define at least one argument for the procedure it defines.
![Page 11: 1 VBScript Session 17. 2 What we learn last session?](https://reader033.fdocuments.net/reader033/viewer/2022061304/5513deb655034679748b5340/html5/thumbnails/11.jpg)
11
Classes in VBScriptSet Property Statement
Declares, in a Class block, the name, arguments, and code that form the body of a Property procedure that sets a reference to an object.
Syntax
[Public [Default] | Private] Property Set name ([arglist,] reference) [statements] [[Set] name = expression] [Exit Property] [statements]
End Property
![Page 12: 1 VBScript Session 17. 2 What we learn last session?](https://reader033.fdocuments.net/reader033/viewer/2022061304/5513deb655034679748b5340/html5/thumbnails/12.jpg)
12
Classes in VBScriptSet Property Statement
If not explicitly specified using either Public or Private, Property Set procedures are public by default, that is, they are visible to all other procedures in your script.
The value of local variables in a Property Set procedure is not preserved between calls to the procedure.
You can't define a Property Set procedure inside any other
The Exit Property statement causes an immediate exit from a Property Set procedure.
Every Property Set statement must define at least one argument for the procedure it defines.
![Page 13: 1 VBScript Session 17. 2 What we learn last session?](https://reader033.fdocuments.net/reader033/viewer/2022061304/5513deb655034679748b5340/html5/thumbnails/13.jpg)
13
Classes in VBScriptInitialize Event
Occurs when an instance of the associated class is created.
Syntax
Private Sub Class_Initialize() statements
End Sub
Set X = New TestClass ' Create an instance of TestClass. Set X = Nothing ' Destroy the instance.
![Page 14: 1 VBScript Session 17. 2 What we learn last session?](https://reader033.fdocuments.net/reader033/viewer/2022061304/5513deb655034679748b5340/html5/thumbnails/14.jpg)
14
Classes in VBScriptTerminate Event
Occurs when an instance of the associated class is terminated.
Syntax
Private Sub Class_Terminate() statements
End Sub
Set X = New TestClass ' Create an instance of TestClass. Set X = Nothing ' Destroy the instance.
![Page 15: 1 VBScript Session 17. 2 What we learn last session?](https://reader033.fdocuments.net/reader033/viewer/2022061304/5513deb655034679748b5340/html5/thumbnails/15.jpg)
15
Classes in VBScriptInline Classes
Inline class is a class that you can immediatelly use without registering the class.
![Page 16: 1 VBScript Session 17. 2 What we learn last session?](https://reader033.fdocuments.net/reader033/viewer/2022061304/5513deb655034679748b5340/html5/thumbnails/16.jpg)
16
Classes in VBScriptMyArray Class - Example
Inline class is a class that you can immediatelly use without registering the class.
VBScript\VBS\class.vbs
![Page 17: 1 VBScript Session 17. 2 What we learn last session?](https://reader033.fdocuments.net/reader033/viewer/2022061304/5513deb655034679748b5340/html5/thumbnails/17.jpg)
17
Creating a COM ClassStep 1
Open a new ActiveX DLL Project in Visual Basic 6
![Page 18: 1 VBScript Session 17. 2 What we learn last session?](https://reader033.fdocuments.net/reader033/viewer/2022061304/5513deb655034679748b5340/html5/thumbnails/18.jpg)
18
Creating a COM ClassStep 2
Rename the project
![Page 19: 1 VBScript Session 17. 2 What we learn last session?](https://reader033.fdocuments.net/reader033/viewer/2022061304/5513deb655034679748b5340/html5/thumbnails/19.jpg)
19
Creating a COM ClassStep 3
Remove the existing empty class
![Page 20: 1 VBScript Session 17. 2 What we learn last session?](https://reader033.fdocuments.net/reader033/viewer/2022061304/5513deb655034679748b5340/html5/thumbnails/20.jpg)
20
Creating a COM ClassStep 4
Open the VB Class builder
![Page 21: 1 VBScript Session 17. 2 What we learn last session?](https://reader033.fdocuments.net/reader033/viewer/2022061304/5513deb655034679748b5340/html5/thumbnails/21.jpg)
21
Creating a COM ClassStep 5
Create a new class
![Page 22: 1 VBScript Session 17. 2 What we learn last session?](https://reader033.fdocuments.net/reader033/viewer/2022061304/5513deb655034679748b5340/html5/thumbnails/22.jpg)
22
Creating a COM ClassStep 6
Add properties, methods, events and enums using the class builder.
![Page 23: 1 VBScript Session 17. 2 What we learn last session?](https://reader033.fdocuments.net/reader033/viewer/2022061304/5513deb655034679748b5340/html5/thumbnails/23.jpg)
23
Creating a COM ClassStep 7
Update the project
![Page 24: 1 VBScript Session 17. 2 What we learn last session?](https://reader033.fdocuments.net/reader033/viewer/2022061304/5513deb655034679748b5340/html5/thumbnails/24.jpg)
24
Save the project and compile the dll.
![Page 25: 1 VBScript Session 17. 2 What we learn last session?](https://reader033.fdocuments.net/reader033/viewer/2022061304/5513deb655034679748b5340/html5/thumbnails/25.jpg)
Make sure to visit us
Tutorials Articles Proikects And much more
www.AdvancedQTP.com
25