Example of class in Vbscripting – User friendly Tech help
Here is a example for defining a Class, setting the values using Property and working with methods using Object of class.
‘********************************Code for Class********************************
n‘Defining a Class
n
Class UFTHelp
n
‘Declaring variables inside class
n
Private sTool,sVersion
n
‘Using Let property for Setting the values of class members
n
Public property Let Tool (sUFT)
n
Select case sUFT
n
Case “UFT”
n
sTool = sUFT
n
Case “QTP”
n
sTool = sUFT
n
Case Else
n
Msgbox “Please enter Correct Tool to learn”
n
End Select
n
End Property
n
‘Method declaration
n
Public Sub version(sHP)
n
Select case sHP
n
Case “11.5”
n
If sTool = “UFT” Then
n
Msgbox “I want to learn ” &sTool&” “&sHP
n
End If
n
Case “11”
n
If sTool = “QTP” Then
n
Msgbox “I want to learn ” &sTool&” “&sHP
n
End If
n
Case Else
n
Msgbox “Please enter correct Version of Tool”
n
End Select
n
End Sub
n
End Class
n
‘Creating objects of class
n
Dim objHelp
n
Set objHelp = New UFTHelp
n
‘Setting the value of Local variable(Change value of TOOL and version to observe the behaviour)
n
objHelp.Tool= “UFT”
n
‘Calling the methods of class
n
objHelp.version(“11.5”)
n
‘Destroying the object
n
Set objHelp = nothing